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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:27:20+00:00 2026-06-09T07:27:20+00:00

I have the following primary template: template<size_t pos, size_t lev> struct Sol; and I

  • 0

I have the following primary template:

template<size_t pos, size_t lev>
struct Sol;

and I specialize it for some pos values like so:

template<size_t lev>
struct Sol<0, lev>
{
    static const mpl::vector_c<size_t, 4, 6> jumps;
    static const size_t value =
        mpl::fold<jumps, mpl::integral_c<size_t, 0>, 
                  mpl::plus<Sol<_1, lev-1>::value, 
                            Sol<_2, lev-1>::value> >::type::value;
}

but I get that Sol expected size_t and got mpl_::_1. I know in this case I could probably omit this fold thing im trying to do and just declare value to be the sum of the one level lower values of the other two Sol structs for pos of 4 and 6..but I was wondering if this could be repaired in case the vector_c was a bit long to type out?

Thanks..

  • 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-06-09T07:27:21+00:00Added an answer on June 9, 2026 at 7:27 am

    The code below will do what you want. I’ve made a few changes.

    First, I wrapped the pos non-type template parameter with a mpl::integral_c. In general, when using Boost.MPL, it is advised to wrap all your non-type template parameters. This way, you never have to distinguish them later on.

    Second, I used template metafunction forwarding. What this means is that instead of defining a template data member value inside Sol, I simply derive Sol from a Boost.MPL template that contains that value. This will save you typing ::type::value all over the place. Use good indentation to make the code easier to read.

    Third, I wrapped your call to mpl::plus inside mpl::fold with a boost::mpl::lambda. This is not stricly necessary for the code you gave, but it will be if you use Sol itself inside another mpl::fold expression with other placeholder arguments (the lambda wrapping will delay evaluation until the entire template has been parsed).

    Fourth, I made a full specialization to stop the recursion on your lev parameter. BTW, if you ever start doing compile-time computation ons lev, the same advise applies: wrap it first into a mpl::integral_c.

    #include <boost/mpl/fold.hpp>
    #include <boost/mpl/integral_c.hpp>
    #include <boost/mpl/lambda.hpp>
    #include <boost/mpl/placeholders.hpp>
    #include <boost/mpl/plus.hpp>
    #include <boost/mpl/vector_c.hpp>
    
    namespace mpl = boost::mpl;
    using namespace mpl::placeholders;
    
    // primary template
    template<typename pos, size_t lev>
    struct Sol;
    
    // partial specialization for zero position
    template<size_t lev>
    struct Sol< mpl::integral_c<size_t, 0>, lev>
    :
            mpl::fold<
                    mpl::vector_c<size_t, 4, 6>, 
                    mpl::integral_c<size_t, 0>,
                    mpl::lambda<
                            mpl::plus<
                                    Sol<_1, lev-1>, 
                                    Sol<_2, lev-1>
                            > 
                    > 
            >        
    {};
    
    // full specialization for zero position and level
    template<>
    struct Sol< boost::mpl::integral_c<size_t, 0>, 0>
    :
            boost::mpl::integral_c<size_t, 0> // or whatever else you need
    {};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: id INT (PRIMARY) score INT I'd like to know,
I have the following table and values: create table TreeTable ( ID int primary
I have the following pseudo-SQL schema: table flight id int primary key date timestamp
I have the following tables: create table TableA ( Id int primary key identity,
I have the following defining a table: CREATE TABLE players(playerid INTEGER PRIMARY KEY AUTOINCREMENT
I have the following MySQL/InnoDB table. I added a compound index as the primary
I have two database tables with the following structure: actions: action_id int(11) primary key
I have following tables: Profiles: ProfileID (Primary Key) ProfileName, etc. Contacts: ContactID (Primary Key)
Assume I have the following tables ( **bold** - primary key, *italics* - foreign
In a MySQL database I have a table with the following primary key PRIMARY

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.