Boost logo

Boost Users :

From: Chris Weed (chrisweed_at_[hidden])
Date: 2007-11-08 15:59:09


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net