2

I'm trying to do a POC of policy based design using the boost-mpl's map container. (code here)

I pass my policies around using an mpl::map, which is empty by default :

typedef boost::mpl::map<> DefaultPolicy;

To get the policy I tried the following:

typedef typename boost::mpl::at<TPolicy, LogPK, DefaultLogP>::type LoggingPolicy;

Instead, I'm getting the following error with g++ 4.81 (and an equivalent one with clang++ 3.3):

main.cpp:49:61: error: wrong number of template arguments (3, should be 2)
    typedef typename boost::mpl::at<TPolicy, LogPK, DefaultLogP>::type LoggingPolicy;
                                                               ^

The boost documentation mentions a three-arguments overload for the at template. It looks like it's not located in #include <boost/mpl/at.hpp>. I even searched this overload throught the boost code, without success. The only template I found is the one with two arguments. I failed at googling this issue ("at" is too common).

Is it a boost documentation bug, or has anyone found out how to use this mpl::at overload ?

1
  • 1
    facepalm. I've finally found the trac issue of this (at least) three years old documentation bug. Commented Jul 8, 2013 at 21:37

1 Answer 1

2

There's only the 2-type version. The documentation is unfortunately wrong and has been forever. But you can always roll your own

template <typename Seq, typename Key, typename Def>
struct at_def
: mpl::eval_if<
    typename mpl::has_key<Seq, Key>::type,
    mpl::at<Seq, Key>,
    mpl::identity<Def>
    >
{ }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.