daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. How to figure out the return type of a vector of nviews
  2. template <int N, typename T>
  3. /*what is the return type*/ nviewgetter( T const& t )
  4. {
  5.  
  6.     typename T::const_iterator it(t.begin());
  7.  
  8.     typedef BOOST_TYPEOF_TPL(*it) etype;
  9.     typedef typename boost::fusion::result_of::as_nview<etype, N>::type netype;
  10.     std::vector<netype> r;
  11.  
  12.     while(it!=t.end()){
  13.         r.push_back( boost::fusion::as_nview<N>(*it) );
  14.         it++;
  15.     }
  16.  
  17.     //return r;
  18. }
  19.    
  20. template <int N, typename T>
  21. struct nviewgetter_traits
  22. {
  23.     typedef BOOST_TYPEOF_TPL(typename T::value_type) etype;
  24.     typedef typename boost::fusion::result_of::as_nview<etype, N>::type netype;
  25.     typedef std::vector<netype> result_type;
  26.  
  27.     // Or combine it into a single monstrosity if you prefer:
  28.     // typedef std::vector<
  29.     //    typename boost::fusion::result_of::as_nview<
  30.     //        BOOST_TYPEOF_TPL(typename T::value_type), N
  31.     //    >::type> result_type;
  32. };
  33.  
  34. template <int N, typename T>
  35. typename nviewgetter_traits<N,T>::result_type nviewgetter(T const & t)
  36. {
  37.     typename nviewgetter_traits<N,T>::result_type r;
  38.     for (auto it = t.begin(); it != t.end(); ++it) {
  39.         r.push_back( boost::fusion::as_nview<N>(*it) );
  40.     }
  41.     return r;
  42. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top