0

I have been stuck in the code for a while. I can work around the issue but feel very bad if I cannot even get the code to compile. The problems were described in the code.

namespace fusion = boost::fusion;


  template <int N, typename T>
  struct viewTraits
  {

    typedef typename T::value_type value_type;

    typedef typename fusion::result_of::as_nview<value_type, N>::type view_type;

    typedef std::vector<view_type> result_type;
  };


  int main ()
  {

    typedef boost::fusion::vector<int, double> VecType;

    typedef std::vector<VecType> Matrix;

    typedef viewTraits<0, Matrix>::result_type R;

    Matrix m (20);
    for (int i = 0; i < 20; ++i)
    {
      m[i] = VecType (i, i+0.1*i);
    }
    R r;

    /*
    * the following can compile, but not what I want
    */
    BOOST_FOREACH (Matrix::value_type v, m)
    {
      r.push_back (fusion::as_nview <0>(v) );
    }

    /*
    * the following cannot compile???, why???
    */
    BOOST_FOREACH (Matrix::value_type const &v, m)
    {
      r.push_back (fusion::as_nview <0>(v) );
    }
  }

Please anyone can point out what I have missed.

Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
Wood
  • 1
  • What was the compiler error message? –  Aug 26 '12 at 09:41
  • no matching function for call to âstd::vector, boost::mpl::vector_c >, std::allocator, boost::mpl::vector_c > > >::push_back(boost::fusion::nview, boost::mpl::vector_c >)stl_vector.h:602: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = nview – Wood Aug 26 '12 at 11:13

1 Answers1

0

BOOST_FOREACH expects the loop variable as first parameter so that can't be const (and it is picky about commas since it is a macro). Take a look at the documented pitfalls.