提升不返回类型

Mat*_*tia 1 c++ boost template-meta-programming

我有以下代码无法编译:

#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;
}
Run Code Online (Sandbox Code Playgroud)

代码正在使用Apple LLVM clang 4.1编译器和boost 1.5.2编译,错误是"类型参数的模板参数必须是类型" - 基本上编译器抱怨boost::mpl::at没有返回类型.违规代码几乎是从boost文档中逐字记录下来的,所以我对这有什么问题感到茫然(据我所知,boost::mpl::at它会返回一个类型).

jua*_*nza 5

你需要

typename at< typeset, T >::type
Run Code Online (Sandbox Code Playgroud)

因为它取决于模板参数T.所以你必须告诉编译器type这个上下文中的类型.