Iterating over Boost fusion::vector

前端 未结 4 1652
萌比男神i
萌比男神i 2021-01-16 05:33

I\'m trying to iterate over a boost::fusion vector using:

typedef typename fusion::result_of::begin::type t_iter;
  std::cout << distance(begi         


        
4条回答
  •  春和景丽
    2021-01-16 06:22

    You can't just iterate a Fusion vector like that, the type for each iterator may be different than the previous one (and usually is). I guess that's why you don't have it = next(it) in your code, it would give a compilation error.

    You could use boost::fusion::for_each for this, together with a function object that prints each element to the standard output:

    struct print
    {
        template< typename T >
        void operator()( T& v ) const
        {
            std::cout << v;
        }
    };
    
    ...
    
    boost::fusion::for_each( t, print() );
    

提交回复
热议问题