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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:36:19+00:00 2026-06-02T13:36:19+00:00

Given: typedef boost::mpl::vector<Type1, Type2, Type3> types; const size_t numTypes = boost::mpl::size<types>::value; std::array<std::function<bool(const obj&, const

  • 0

Given:

typedef boost::mpl::vector<Type1, Type2, Type3> types;
const size_t numTypes = boost::mpl::size<types>::value;
std::array<std::function<bool(const obj&, const obj&)>, numTypes*numTypes> arr;

I’m trying to get this sort of functionality in compile time:

for( size_t i = 0; i < numTypes; ++i )
{
    for( size_t j = 0; j < numTypes; ++j )
    {
        arr[i*numTypes+j] = ObjPair<boost::mpl::at_c<vecType, i>::type, boost::mpl::at_c<vecType, j>::type>::Foo;
    }
}

I think it would look something like:

std::array<std::function<bool(const obj&, const obj&)>, numTypes*numTypes> arr = { BOOST_PP_FOR((0, numTypes), PRED, OP, MACRO) };

But I can’t get it working (I didn’t post my full failed attempt at using BOOST_PP_FOR).

ObjPair<T1, T2>::Foo is a static method of signiture bool(const obj&, const obj&). It’s specialized for different obj types.

I would be using this array to find a particular function given pairs of objects. The objects are held as their base classes, and I can index the array with some math to determine the index based on IDs available in the base class.

  • 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-02T13:36:20+00:00Added an answer on June 2, 2026 at 1:36 pm

    It is not possible for PP to iterate over boost::mpl::vector size. Hovewer you can try define it.

    typedef boost::mpl::vector<bool, short, long> vecType;
    #define numTypes 3
    

    I have no TR1 so I try with boost array:

    typedef  boost::function<bool(const obj&, const obj&)> Function;
    typedef boost::array<Function, numTypes*numTypes> FooArray;
    
    #define OBJPAIR_FOO_ARRAY(z, n, text)  BOOST_PP_COMMA_IF(n) &ObjPair<      \
    boost::mpl::at_c<vecType, n/numTypes>::type,  \
    boost::mpl::at_c<vecType, n%numTypes>::type   \
        >::Foo
    
    FooArray fooArray= {
        BOOST_PP_REPEAT( BOOST_PP_MUL(numTypes, numTypes) , OBJPAIR_FOO_ARRAY, )
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a struct, e.g. typedef struct { int value; } TestStruct; Why does the
Given definitions: typedef typename boost::graph_traits::adjacency_iterator adjacency_iter; typedef typename boost::inv_adjacency_iterator_generator::type inv_adjacency_iter; I am interested in
I am new to boost and metaprogramming so my problem is this: typedef fusion::vector<int,
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I
Given two structure in c: typedef struct _X_ { int virtual_a; int virtual_b; void
Given the following piece of code: template<typename T> class MyContainer { typedef T value_type;
I started to play around with the boost fusion and mpl library and got
I'm using a boost::multi_array and when I need to check if a given coordinate
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;

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.