Newbie and his template for comments.
Hello.
I'm a C++ developer, who is learning STL recently, and loving it :)
I've encountered Boost library, which seems to extending STL funcationality
a lot :) I've also created a sampel template for usage in my company,
and I would like to get comments about it: is this code ok, exception
safe, somebody did it better things like that.
In my projects I'm often using structures like map
--- In Boost-Users@y..., "Kamil Burzynski"
[...] I've also created a sampel template for usage in my company, and I would like to get comments about it: is this code ok, exception safe, somebody did it better things like that.
It's so useful that it's already in Boost. :)
for_each( my_map.begin(), my_map.end(), map_fun( &Point::Reset ) );
for_each(my_map.begin(), my_map.end(), boost::bind(&Point::Reset, _1)); See also boost/function.hpp and lambda/lambda.hpp. Cool stuff! Ken
"kthomases"
for_each(my_map.begin(), my_map.end(), boost::bind(&Point::Reset, _1));
Does this bound function actually select the pair's "second" member to call the function on? It looks at though it will fail to compile, expecting the applied first argument to be convertible to the UDT Point. -- Steven E. Harris :: seharris@raytheon.com Raytheon :: http://www.raytheon.com
On Monday 05 August 2002 03:40 am, Kamil Burzynski wrote:
for_each( my_map.begin(), my_map.end(), map_fun( &Point::Reset ) );
Boost.Bind can do that:
for_each(my_map.begin(), my_map.end(),
bind(&Point::Reset,
bind(&map
Douglas Gregor
Boost.Bind can do that:
for_each(my_map.begin(), my_map.end(), bind(&Point::Reset, bind(&map
::value_type::second, _1))); So can Boost.Lambda:
for_each(my_map.begin(), my_map.end(), bind(&Point::Reset, (&_1)->*&map
::value_type::second));
Again, I can't see how this can work. "second" is the name of a member, not a function. You need a "pair select functor" to grab the first or second member from a pair. I've written a couple of these to use in conjunction with the projection_iterator adaptor. template <class P> struct select_pair_first : public std::unary_function
{ inline result_type& operator()(argument_type& arg) const { return arg.first; } inline const result_type& operator()(const argument_type& arg) const { return arg.first; } }; template <class P> struct select_pair_second : public std::unary_function
{ inline result_type& operator()(argument_type& arg) const { return arg.second; } inline const result_type& operator()(const argument_type& arg) const { return arg.second; } }; -- Steven E. Harris :: seharris@raytheon.com Raytheon :: http://www.raytheon.com
On Wednesday 07 August 2002 02:27 pm, Steven E. Harris wrote:
Douglas Gregor
writes: Boost.Bind can do that:
for_each(my_map.begin(), my_map.end(), bind(&Point::Reset, bind(&map
::value_type::second, _1))); So can Boost.Lambda:
for_each(my_map.begin(), my_map.end(), bind(&Point::Reset, (&_1)->*&map
::value_type::second)); Again, I can't see how this can work. "second" is the name of a member, not a function. You need a "pair select functor" to grab the first or second member from a pair. I've written a couple of these to use in conjunction with the projection_iterator adaptor.
It works, I promise :) Boost.Bind has an overload that supports pointers to data members by automagically transforming them into unary function objects. Boost.Lamda overloads the ->* operator for pointers to data members. Doug
Douglas Gregor
It works, I promise :)
Boost.Bind has an overload that supports pointers to data members by automagically transforming them into unary function objects.
Wow. What does the syntax look like for deducing when an argument is of type pointer to member variable? -- Steven E. Harris :: seharris@raytheon.com Raytheon :: http://www.raytheon.com
participants (4)
-
Douglas Gregor
-
Kamil Burzynski
-
kthomases
-
Steven E. Harris