|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-03-09 07:59:17
John Torjo wrote:
> Sorry, I mis-explained.
> For boost::bind, the above works like a bliss.
>
> It will have problems working with other code, that uses result_type.
> For example, boost::transform_iterator:
>
> #include <boost/bind.hpp>
> #include <boost/iterator/transform_iterator.hpp>
> using namespace boost;
> #include <algorithm>
> #include <vector>
> #include <string>
>
> struct test { std::string s; };
>
> void clear_s( std::string & s) { s.erase(); }
>
> int main(int argc, char* argv[])
> {
> std::vector<test> v;
> std::for_each(
> // of course, it would be simpler to use Range Template
> Library :D
> make_transform_iterator(v.begin(),mem_fn(&test::s)),
> make_transform_iterator(v.end(),mem_fn(&test::s)), clear_s);
>
> return 0;
> }
Your examples are getting more and more contrived. ;-)
To override the result_type, you'll need once again to revert to
bind<std::string&>(mem_fn(&test::s), _1)
instead of mem_fn(&test::s).
If you do a "cvs update" you'll also be able to shorten it to
bind<std::string&>(&test::s, _1)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk