I have the following code that is failing to compile:
#include <iostream>
#include "boost/mpl/set.hpp"
#include "boost/mpl/at.hpp"
#include "boost/type_traits/is_same.hpp"
struct TypeSet {
typedef boost::mpl::set<int, float> typeset;
template<typename T>
static bool hasType()
{
using namespace boost;
using namespace boost::mpl;
return is_same< at< typeset, T >::type, T >::value; // <-- ERROR IS HERE
}
};
int main(int argc, const char * argv[])
{
bool hasInt = TypeSet::hasType<int>();
std::cout << (hasInt ? "set contains int" : "set does not contain int") << std::endl;
return 0;
}
The code is being compiled with the Apple LLVM clang 4.1 compiler and boost 1.5.2 and the error is “Template argument for type parameter must be a type” – basically the compiler is complaining that boost::mpl::at is not returning a type. The offending code is taken pretty much verbatim from the boost documentation so I’m at a loss as to what’s wrong with this (and as far as I can tell boost::mpl::at does return a type).
You need
since it depends on template parameter
T. So you have to tell the compiler thattypeis a type in this context.