Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6946061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:30:59+00:00 2026-05-27T13:30:59+00:00

I have the following problem: template <int N, typename T> /*what is the return

  • 0

I have the following problem:

template <int N, typename T>
/*what is the return type*/ nviewgetter( T const& t )
{

    typename T::const_iterator it(t.begin());

    typedef BOOST_TYPEOF_TPL(*it) etype;
    typedef typename boost::fusion::result_of::as_nview<etype, N>::type netype;
    std::vector<netype> r;

    while(it!=t.end()){
        r.push_back( boost::fusion::as_nview<N>(*it) );
        it++;
    }

    //return r;
}

What is expected is that T is a sequence of Forward Sequences (e.g. boost::fusion::vector) and I want to get a view of the N-th element in each element of T . However, I do not know from beforehand the type of boost::fusion::vector , e.g. boost::fusion::vector<int, double> or boost::fusion::vector<int, double, std::string> . In the code I can figure out the correct type but I cannot figure out this in the function declaration.

Thanks !

Any suggestions for code improvement are also welcome. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:31:00+00:00Added an answer on May 27, 2026 at 1:31 pm

    If you don’t want to write the full type out, you could move the type definitions into a separate template, so that they are available when you declare the function template; something like:

    template <int N, typename T>
    struct nviewgetter_traits
    {
        typedef BOOST_TYPEOF_TPL(typename T::value_type) etype;
        typedef typename boost::fusion::result_of::as_nview<etype, N>::type netype;
        typedef std::vector<netype> result_type;
    
        // Or combine it into a single monstrosity if you prefer:
        // typedef std::vector<
        //    typename boost::fusion::result_of::as_nview<
        //        BOOST_TYPEOF_TPL(typename T::value_type), N
        //    >::type> result_type;
    };
    
    template <int N, typename T>
    typename nviewgetter_traits<N,T>::result_type nviewgetter(T const & t)
    {
        typename nviewgetter_traits<N,T>::result_type r;
        for (auto it = t.begin(); it != t.end(); ++it) {
            r.push_back( boost::fusion::as_nview<N>(*it) );
        }
        return r;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: template<typename _Tp> std::string string_from_number(_Tp number, int precision = 5)
I have a problem with nested templates and their template specialization. Given the following
So given the following template functions with partial specialization template<typename T> void foo(vector<T> &in)
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have a base class that looks like the following: template<typename T> class Base
I have the following class template<typename hi_t, typename lo_t> struct int_t { hi_t hi;
i have some trobles with the following code: #include <iostream> #incldue <vector> template <typename
I have the following problem with inheritance and templates: class Base {}; class Deriv
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.