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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:34:04+00:00 2026-05-30T16:34:04+00:00

Consider the following code that automates generation of Boost.MPL type sequences (list or vector).

  • 0

Consider the following code that automates generation of Boost.MPL type sequences (list or vector).

    #include <iostream>                     // cout
    #include <boost/mpl/for_each.hpp>       // for_each
    #include <boost/mpl/identity.hpp>       // identity, make_identity
    #include <boost/mpl/int.hpp>            // int_
    #include <boost/mpl/list.hpp>           // list
    #include <boost/mpl/next.hpp>           // next
    #include <boost/mpl/push_front.hpp>     // push_front
    #include <boost/mpl/vector.hpp>         // vector

    template<size_t, typename> struct iota_n;

    template<typename Value>
    struct iota_n<0, Value>
    :
            boost::mpl::list<>      // can change this to boost::mpl::vector<>
    {};

    template<size_t N, typename Value>
    struct iota_n
    :
            boost::mpl::push_front< typename
                    iota_n< 
                            N - 1, typename
                            boost::mpl::next<Value>::type
                    >::type,
                    Value
            >
    {};

    // works for N <=  20 and boost::mpl::vector
    // works for N <= 247 and boost::mpl::list
    typedef iota_n< 247, boost::mpl::int_<0> >::type sequence;

    struct print
    {
            template<typename T>
            void operator()(boost::mpl::identity<T>)
            {
                    std::cout << T::value << "\n";
            }
    };

    int main()
    {
            boost::mpl::for_each<sequence, boost::mpl::make_identity<> >(
                    print()
            );
            std::cout << BOOST_MPL_LIMIT_LIST_SIZE << '\n';         // 20 on my system
            std::cout << BOOST_MPL_LIMIT_VECTOR_SIZE << '\n';       // 20 on my system
            return 0;
    }

According to the Boost.MPL documentation, a boost::mpl::list sequence can have up to BOOST_MPL_LIMIT_LIST_SIZE elements, and similarly for a boost::mpl::vector the compiler can go up to BOOST_MPL_LIMIT_VECTOR_SIZE. Both macros evaluate to 20 on my system.

MSVC++ 2010 and Boost 1.47.0 indeed cannot generate vectors with more than the documented 20 elements. What is surprising that it can, however, generate lists with up to 247 elements!

Does anyone know why this happens?

  • 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-30T16:34:05+00:00Added an answer on May 30, 2026 at 4:34 pm

    As per the docs, BOOST_MPL_LIMIT_xxx_SIZE specifies the limit for the sequence’s variadic form (e.g. list<>); the numbered form (e.g. list42<>), has no predefined top limit, aside from compiler limitations on the number of template parameters. Okay, the latter statement is not completely accurate: in practice, in the default library configuration, there is a limit on the numbered forms imposed by using pre-generated preprocessed headers; see this post on how to lift it.

    FOLLOW UP: @rhalbersma You seem to be bundling together two separate notions: the maximum number of list elements vs. the maximum arity of the list‘s “constructor”. BOOST_MPL_LIMIT_LIST_SIZE controls the latter, not the former, and there is really no dependency between the two. Your code above is testing the former; maximum template arity is a totally different beast.

    The reason there is an arity limit for MPL sequences in the first place is that the library had to emulate variadic templates (it was written way before C++11), which is typically done by defaulting unused arguments to some auxiliary type and providing a bunch of specializations to weed out those unused arguments before constructing the actual sequence. The cost of this is that the default arguments typically show up in error messages and obscure everything else, and a large number of specializations has noticeable effect on compilation times. IOW, you had to stop somewhere, and at the time it seemed unlikely that you’d often need to pass more than 20 sequence elements to a sequence’s “constructor” (and if you did, there are always numbered forms), hence the current limits.

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

Sidebar

Related Questions

Consider the following code sample that uses MEF to create an object of type
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider the following code. It's an anchor tag with an id called leader-module-total that
Consider the following code: while(true) { someFunction(); Thread.sleep(1000); } What I want is that,
Sometimes JavaScript doesn't make sense to me, consider the following code that generates a
Consider the following code (from a requirement that says that 3 is special for
Consider the following code, the first demonstrates that the cleanup executes when we're finished
Consider the following code snippet that takes user input (a date) and format it
Please consider the following code: type TFoo1 = class public procedure DoSomething1; end; TFoo2
Consider the following code that writes the same value to the same memory location

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.