[iterator] readable and writable transform_iterator
I can't figure out how to make a writable transform_iterator work. Here is what I have: #include <boost/iterator/transform_iterator.hpp> #include <boost/tuple/tuple.hpp> #include <vector> template< int N > struct Get { template<typename T> struct result; template<int M,typename T> struct result<Get<M>(T&)> { typedef typename boost::reference_wrapper<typename boost::tuples::element<M,T>::type>::type type; }; template<typename Tup> typename result<Get<N>(Tup&)>::type operator()(Tup& t) { return boost::tuples::get<N>(t); } }; int main() { std::vector<boost::tuple<int,float> > v1; v1.push_back(boost::make_tuple(1,2.2f)); v1.push_back(boost::make_tuple(2,3.2f)); std::vector<boost::tuple<int,float> > v2(2); std::copy(boost::make_transform_iterator(v1.begin(),Get<0>()), boost::make_transform_iterator(v1.end(),Get<0>()), boost::make_transform_iterator(v2.begin(),Get<0>())); } g++ seems to get hung up on figuring out the result type of Get<0>. Any help would be greatly appreciated. Chris
Chris Weed wrote:
template< int N > struct Get { template<typename T> struct result;
transform_iterator doesn't make use of boost::result_of, IIRC. You have to define a nested `result_type` in `Get`, or you can use transform_iterator<..., a_result_type>. Regards, -- Shunsuke Sogame
When I looked through the code in SVN, it appears you are right. Unfortunately, the docs say it uses result_of. Thanks, Chris On Nov 9, 2007 4:28 AM, shunsuke <pstade.mb@gmail.com> wrote:
Chris Weed wrote:
template< int N > struct Get { template<typename T> struct result;
transform_iterator doesn't make use of boost::result_of, IIRC. You have to define a nested `result_type` in `Get`, or you can use transform_iterator<..., a_result_type>.
Regards,
-- Shunsuke Sogame
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
on Fri Nov 09 2007, "Chris Weed" <chrisweed-AT-gmail.com> wrote:
When I looked through the code in SVN, it appears you are right. Unfortunately, the docs say it uses result_of. Thanks, Chris
Chris, Could you file a bug report about this at http://svn.boost.org ("New Ticket") so I don't forget to address it? Thanks, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
It put me in as anonymous, but the ticket is here: http://svn.boost.org/trac/boost/ticket/1427 Chris On Nov 14, 2007 1:09 PM, David Abrahams <dave@boost-consulting.com> wrote:
on Fri Nov 09 2007, "Chris Weed" <chrisweed-AT-gmail.com> wrote:
When I looked through the code in SVN, it appears you are right. Unfortunately, the docs say it uses result_of. Thanks, Chris
Chris,
Could you file a bug report about this at http://svn.boost.org ("New Ticket") so I don't forget to address it?
Thanks,
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
on Wed Nov 14 2007, "Chris Weed" <chrisweed-AT-gmail.com> wrote:
It put me in as anonymous, but the ticket is here: http://svn.boost.org/trac/boost/ticket/1427
The cure for that is to sign in to Trac. See the instructions at http://svn.boost.org for creating tickets. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
on Thu Nov 08 2007, "Chris Weed" <chrisweed-AT-gmail.com> wrote:
I can't figure out how to make a writable transform_iterator work.
Without getting too far into your code, you need to make sure that the function (object) you use returns a reference, not a value. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (3)
-
Chris Weed
-
David Abrahams
-
shunsuke