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 3286698
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:24:35+00:00 2026-05-17T20:24:35+00:00

For a little library project I’m using boost::tuple. Right now, I’m facing the problem

  • 0

For a little library project I’m using boost::tuple. Right now, I’m facing the problem of turning a “cons list” I operated on via metaprogramming back to a boost::tuple<…> type. The “dirty” solution would be to provide lots of partial specialications a la

template<class T> struct id{typedef T type;};

template<class TL> struct type_list_to_tuple_type;

template<class T1>
struct type_list_to_tuple_type<
    boost::tuples::cons<T1,boost::tuples::null_type>
> : id<boost::tuple<T1> > {}

template<class T1, class T2>
struct type_list_to_tuple_type<
    boost::tuples::cons<T1,
    boost::tuples::cons<T2,boost::tuples::null_type> >
> : id<boost::tuple<T1,T2> > {}

template<class T1, class T2, class T3>
struct type_list_to_tuple_type<
    boost::tuples::cons<T1,
    boost::tuples::cons<T2,
    boost::tuples::cons<T3,boost::tuples::null_type> > >
> : id<boost::tuple<T1,T2,T3> > {}

...

But this is tedious and error-prone, especially because I need support for tuples with possibly many elements. These tuple types are automatically generated via operator overloading. If possible, I’d like to avoid having to write so many specializations.

Any idea on how to do that without any C++0x features? I suppose it’s not possible. But maybe I’m overlooking something.

Edit: I actually tried this with the experimental C++0x support only to find out that it doesn’t yet work:

template<class TPH>
class type_pack_holder_to_tuple_type;

template<class...Types>
class type_pack_holder_to_tuple_type<
        type_pack_holder<Types...> >
: id< boost::tuple<Types...> > {};

G++ 4.5.1 says:

sorry, unimplemented: cannot expand 'Types ...' into
a fixed-length argument list

🙁

  • 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-17T20:24:36+00:00Added an answer on May 17, 2026 at 8:24 pm

    If you’re doing template metaprogramming and you need conversion from typelists to tuple, maybe you should consider using Boost.MPL and Boost.Fusion. The former provides a set of compile-time containers and algorithms to manipulate list of times, and the latter make the link between pure compile-time (MPL) and pure runtime (STL) by providing “hybrid” containers and algorithms, that can be operated on either at compile-time through template metaprogramming, or at runtime as tuples.

    However, to answer your question, I don’t think you need to transform your cons list into a tuple since the tuple class is only a convenience to declare tuple more easily. In fact, tuple simply inherits from its corresponding cons list, e.g. tuple<int, float> inherits from cons<int, cons<float, null_type> > without adding any member data or functions. So basically, when you declare a tuple, the library “creates” the corresponding cons list; since you already creates your own cons list, you don’t need the tuple class anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have little problem with boost::asio library. My app receive and process data asynchronously,
I'm a little confused about how the standard library will behave now that Python
My little site should be pooling list of items from a table using the
My little brother is just getting into programming, and for his Science Fair project,
I'm going to write a little library and after the UI for agregating and
I'm merging a static library (assimp) into an existing project (Spring RTS) where both
I'm doing one litle project with JSP for topic Library. I want to create
I am making a little library(DLL) to manage users and their roles/privileges. The plan
I want to share my Xcode project as a static library for other people
I have a maven library project with some classes to deal xml messages. Whenever

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.