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

  • SEARCH
  • Home
  • 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 1111629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:34:39+00:00 2026-05-17T02:34:39+00:00

I started to play around with the boost fusion and mpl library and got

  • 0

I started to play around with the boost fusion and mpl library and got stuck with a quite simple problem.

I declared the following types:

typedef boost::mpl::vector<char, int, long>   TypeVector;
typedef boost::fusion::vector<char, int, long> FusionVector_t;

Now I wanted to write a function that gets me the value from the FusionVector.

template<size_t N typename T>
T getValue(FusionVector_t fvec)
{
    return boost::fusion::at_c<N>(fvec);
}

The function works as expected but I would like to get the index from the boost::mpl vector and use it in this function and not pass it to the function as a template parameter.
But I did not figure out so far how to do this.

Could someone give me a hint?

  • 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-17T02:34:40+00:00Added an answer on May 17, 2026 at 2:34 am

    You can use the find algorithm to get an “iterator” pointing to the first occurence of a type in an MPL sequence. Something like:

    typedef boost::mpl::find<TypeVector, T>::type MplIter;
    

    and then query the fusion vector at that “iterator”‘s position:

    return boost::fusion::at_c<MplIter::pos::value>(fvec);
    

    However, I don’t see why you use the MPL vector at all. IIUC, you’d like to define getValue as:

    template<class T>
    T getValue(FusionVector_t fvec)
    {
      typedef boost::mpl::find<TypeVector, T>::type MplIter;
      return boost::fusion::at_c<MplIter::pos::value>(fvec);
    }
    

    which can work only if TypeVector and FusionVector_t “contain” the same sequence of types. In that case, why not only use FusionVector_t and write:

    template<class T>
    T getValue(FusionVector_t fvec)
    {
      return *boost::fusion::find<T>(fvec);
    }
    

    Moreover, if you want to use “T” as an “index” into the Fusion sequence, this only makes sense if a given type appears only once in the sequence. A fusion::set would thus seem more appropriate than a vector. In that case, you’d have:

    typedef boost::fusion::set<char, int, long> FusionSet_t;
    
    template<class T>
    T getValue(FusionSet_t fset)
    {
      return boost::fusion::at_key<T>(fset);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started to play around with boost python a bit and ran into
I have started to play around with knockoutjs and do some simple binding/dependant binding.
I'm getting started with Play 2.0 by following along with the tutorial. I'm hitting
I started to play around with knockout.js and in doing so I used the
I have recently started to play around with Haxe and Three.js. How do I
I just started using dojo and just started to play around with it. Basically
Just started to play around with node.js, have some past experience with JavaScript but
I just started messing around with Play 2 . I recently learned how to
Hey there, I've started to play around with Fluent NHibernate and now I want
This might sound very basic, but I have just started to play around with

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.