Boost logo

Boost Users :

From: Küppers, Ben (ben.kuppers_at_[hidden])
Date: 2007-01-18 09:22:20


Gents,

For illustration purposes I created the following code that iterates through a sequence and accumulates the distances between the current iterator and the beginning of the sequence. Somehow this code works for normal ranges (range1 and range2) but fails to compile for joint_view range3 (80-plus errors). Changing the call to distance to compare between begin and end or between _2 and _2 (self) works. I am at a loss here. Can someone point out what I am doing wrong?

Thanks
Ben

#include <iostream>

#include <boost/mpl/arithmetic.hpp>
#include <boost/mpl/begin.hpp>
#include <boost/mpl/distance.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/iter_fold.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/vector_c.hpp>

namespace mpl = boost::mpl;

template< class _Sequence >
struct distances {
   typedef typename mpl::iter_fold<
      _Sequence,
      mpl::long_< 0 >,
      mpl::plus<
         mpl::_1,
         mpl::distance<
            typename mpl::begin< _Sequence >::type,
// typename mpl::end< _Sequence >::type
// mpl::_2,
            mpl::_2
>
>
>::type type;
};

int main( int argc, char* argv[] )
{
   typedef mpl::range_c< char, 'a', 'd' >::type range1;
   typedef mpl::range_c< char, 'm', 'q' >::type range2;
   typedef mpl::joint_view< range1, range2 >::type range3;
   typedef distances< range3 >::type type1;

   std::cout << type1();

   std::cout << std::endl;

   return 0;
}

This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.


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