[Range] and [MemberFunction]

In the documentation of Boost.MemberFunction it suggests that a useful purpose for it would be to implement overloads of std algorithms, and indeed other similar algorithms such that the final callable parameter could be a simple pointer to member. struct X { bool method( ); }; std::vector<X> xs; for_each( xs.begin( ), xs.end( ), & X::method ); or from Boost.Range boost::for_each( xs, &X::method ); Is such a facility implemented anywhere in Boost? Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility, so I can say, for example for_each( xs | filtered( & X::method ), doSomething ); rather than, as at present, for_each ( xs | filtered( bind( & X::method, _1 ) ), doSomething ); and similarly for transformed. Thanks, - Rob.

On Tue, Mar 13, 2012 at 3:29 PM, Robert Jones <robertgbjones@gmail.com>wrote:
In the documentation of Boost.MemberFunction it suggests that a useful purpose for it would be to implement overloads of std algorithms, and indeed other similar algorithms such that the final callable parameter could be a simple pointer to member.
struct X { bool method( ); };
std::vector<X> xs;
for_each( xs.begin( ), xs.end( ), & X::method );
or from Boost.Range
boost::for_each( xs, &X::method );
Is such a facility implemented anywhere in Boost?
Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility, so I can say, for example
for_each( xs | filtered( & X::method ), doSomething );
rather than, as at present,
for_each ( xs | filtered( bind( & X::method, _1 ) ), doSomething );
and similarly for transformed.
Thanks,
- Rob.
What about Boost.Foreach??? http://www.boost.org/doc/libs/1_49_0/doc/html/foreach.html Regards, ovanes

On Tue, Mar 13, 2012 at 3:05 PM, Ovanes Markarian <om_boost@keywallet.com>wrote:
What about Boost.Foreach??? http://www.boost.org/doc/libs/1_49_0/doc/html/foreach.html
I can see how that addresses the 'for_each' examples, though it sidesteps a bit, but not the filtered and transformed issues, which is the real deal for me. Thx, R.

On Tue, Mar 13, 2012 at 4:16 PM, Robert Jones <robertgbjones@gmail.com>wrote:
On Tue, Mar 13, 2012 at 3:05 PM, Ovanes Markarian <om_boost@keywallet.com>wrote:
What about Boost.Foreach??? http://www.boost.org/doc/libs/1_49_0/doc/html/foreach.html
I can see how that addresses the 'for_each' examples, though it sidesteps a bit, but not the filtered and transformed issues, which is the real deal for me.
Thx, R.
Boost offers filter and transform iterators, which can be put into the range ;) http://www.boost.org/doc/libs/1_49_0/libs/iterator/doc/index.html Best Regards, Ovanes

On Tue, Mar 13, 2012 at 3:26 PM, Ovanes Markarian <om_boost@keywallet.com>wrote:
On Tue, Mar 13, 2012 at 4:16 PM, Robert Jones <robertgbjones@gmail.com>wrote:
On Tue, Mar 13, 2012 at 3:05 PM, Ovanes Markarian <om_boost@keywallet.com
wrote:
What about Boost.Foreach??? http://www.boost.org/doc/libs/1_49_0/doc/html/foreach.html
I can see how that addresses the 'for_each' examples, though it sidesteps a bit, but not the filtered and transformed issues, which is the real deal for me.
Thx, R.
Boost offers filter and transform iterators, which can be put into the range ;)
http://www.boost.org/doc/libs/1_49_0/libs/iterator/doc/index.html
Indeed, however if I read it right filter_iterator requires a predicate, just as boost.adaptors.filtered does, and the construction of the predicate from a method requires the explicit use of bind, or mem_fn, whereas I'd hoped to see a facility offering an overload that accepts a pointer-to-member directly. Thx, R.

Robert Jones <robertgbjones@gmail.com> writes:
In the documentation of Boost.MemberFunction it suggests that a useful purpose for it would be to implement overloads of std algorithms, and indeed other similar algorithms such that the final callable parameter could be a simple pointer to member.
struct X { bool method( ); };
std::vector<X> xs;
for_each( xs.begin( ), xs.end( ), & X::method );
or from Boost.Range
boost::for_each( xs, &X::method );
Is such a facility implemented anywhere in Boost?
Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility, so I can say, for example
for_each( xs | filtered( & X::method ), doSomething );
rather than, as at present,
for_each ( xs | filtered( bind( & X::method, _1 ) ), doSomething );
and similarly for transformed.
Thanks,
- Rob.
I don't know Boost.MemberFunction and couldn't find any documentation for it, could you provide a link? But from what I can gather in your message, boost::mem_fn seems to be exactly this: for_each( xs.begin( ), xs.end( ), boost::mem_fn(& X::method) ); Granted, it is not exactly what you want, but gets very close. HTH, Philipp Moeller

On Tue, Mar 13, 2012 at 3:36 PM, Philipp Moeller < philipp.moeller@geometryfactory.com> wrote:
I don't know Boost.MemberFunction and couldn't find any documentation for it, could you provide a link?
But from what I can gather in your message, boost::mem_fn seems to be exactly this:
for_each( xs.begin( ), xs.end( ), boost::mem_fn(& X::method) );
Granted, it is not exactly what you want, but gets very close.
You're there already mem_fn is called 'Member Function' in the front page list. It is exactly the boost::mem_fn syntactic noise I was seeking to avoid. - R.

Robert Jones <robertgbjones@gmail.com> writes:
On Tue, Mar 13, 2012 at 3:36 PM, Philipp Moeller < philipp.moeller@geometryfactory.com> wrote:
I don't know Boost.MemberFunction and couldn't find any documentation for it, could you provide a link?
But from what I can gather in your message, boost::mem_fn seems to be exactly this:
for_each( xs.begin( ), xs.end( ), boost::mem_fn(& X::method) );
Granted, it is not exactly what you want, but gets very close.
You're there already mem_fn is called 'Member Function' in the front page list.
It is exactly the boost::mem_fn syntactic noise I was seeking to avoid.
- R.

Robert Jones <robertgbjones <at> gmail.com> writes:
Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility
Hi Rob, You can find this patch useful: http://boost.2283326.n4.nabble.com/range-adaptors-and-member-functions-point... I hope it will be accepted into Boost.Range some time. Thanks, Maxim

On Wed, Mar 14, 2012 at 2:16 PM, MaximYanchenko <maximyanchenko@yandex.ru>wrote:
Robert Jones <robertgbjones <at> gmail.com> writes:
Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility
Hi Rob, You can find this patch useful:
http://boost.2283326.n4.nabble.com/range-adaptors-and-member-functions-point...
I hope it will be accepted into Boost.Range some time.
Thx Maxim, mainly because I was beginning to think I was talking gibberish!
- Rob.

On Wed, Mar 14, 2012 at 2:16 PM, MaximYanchenko <maximyanchenko@yandex.ru>wrote:
Robert Jones <robertgbjones <at> gmail.com> writes:
Where I'm really going with this, is that I'd like to see versions of Boost.Range adaptors which support the same facility
Hi Rob, You can find this patch useful:
http://boost.2283326.n4.nabble.com/range-adaptors-and-member-functions-point...
I hope it will be accepted into Boost.Range some time.
Hi Maxim - Now that I've digested your patch and the thread you linked to, a question... The patch you've submitted will apply to transformed *and* filtered, possibly others too? Thx, R.
participants (4)
-
MaximYanchenko
-
Ovanes Markarian
-
Philipp Moeller
-
Robert Jones