Gurgeh
Gurgeh

Reputation: 2168

How do I insert into a Boost MPL map

I manage to use Boost MPL vectors and lists just fine, but I just can't figure out maps. When I try to insert into one, I get "too few arguments" from clang 3.1 (gcc 4.7 says something similar). There is a version of insert where the second argument is POS, which is supposed to be ignored, so I tried inserting a dummy type (int) there, but that just gives a new and confusing error.

include <iostream>

#include <boost/mpl/key_type.hpp>
#include <boost/mpl/map.hpp>

using namespace boost;
using namespace mpl;

int main(){

  typedef pair<int_<3>, int_<6>> obj;

  std::cout << key_type<map<>, obj >::type::value << std::endl; //works

  std::cout << has_key<insert<map<>, obj>::type, obj)::type::value << std::endl; //complains on "too few template arguments for class template 'insert'

  std::cout << has_key<insert<map<>, int, obj>::type, obj)::type::value << std::endl; // gives "implicit instantiation of undefined template 'boost::mpl::insert<..."
}

MPL errors aren't exactly helpful, even with clang, so I just don't understand what I am doing wrong here? I am sure it is something silly.

http://www.boost.org/doc/libs/1_51_0/libs/mpl/doc/refmanual/map.html

Upvotes: 1

Views: 1735

Answers (1)

ForEveR
ForEveR

Reputation: 55887

Add

#include <boost/mpl/insert.hpp>

and correct brackets, from ')' to '>'

http://liveworkspace.org/code/afb6632c3eb800412ea551f50c07fb0a

Upvotes: 2

Related Questions