MSVC2010的许多boost模板错误
many boost template errors with MSVC2010
这是代码片段:
#include <boost/utility.hpp>
#include <boost/type_traits.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/typeof/typeof.hpp>
enum ScriptVarType_t { SVT_BOOL, SVT_STRING, SVT_CUSTOM, SVT_CustomWeakRefToStatic };
struct ScriptVar_t {};
struct CustomVar {
struct Ref {};
struct WeakRef {};
};
template<typename T> struct GetType;
template<typename T> struct _GetTypeSimple {
typedef T type;
static type defaultValue() { return T(); }
static const type& constRef(const type& v) { return v; }
};
template<> struct GetType<bool> : _GetTypeSimple<bool> { static const ScriptVarType_t value = SVT_BOOL; };
template<> struct GetType<std::string> : _GetTypeSimple<std::string> { static const ScriptVarType_t value = SVT_STRING; };
template<> struct GetType<CustomVar::Ref> {
typedef CustomVar::Ref type;
static const ScriptVarType_t value = SVT_CUSTOM;
static type defaultValue() { return type(); }
static const type& constRef(const type& v) { return v; }
};
template<typename T>
struct CustomVarWeakRefType {
typedef CustomVar::WeakRef type;
static const ScriptVarType_t value = SVT_CustomWeakRefToStatic;
static CustomVar::Ref defaultValue() { return T().getRefCopy(); }
static CustomVar::WeakRef constRef(const T& v) { return v.thisRef.obj; }
};
struct StringType : GetType<std::string> {};
template<typename T>
struct _SelectType {
static CustomVarWeakRefType<T>* selectType(const CustomVar&) { return NULL; }
static StringType* selectType(const char*) { return NULL; }
static StringType* selectType(char[]) { return NULL; }
typedef typename BOOST_TYPEOF(*selectType(*(T*)NULL)) type;
};
template<typename T> struct GetType : _SelectType<T>::type {};
template<typename T>
T _CastScriptVarConst(const ScriptVar_t& s, T*, typename boost::enable_if_c<(GetType<T>::value < SVT_CUSTOM), T>::type*) {
return (T) s;
}
template<typename T>
T _CastScriptVarConst(const ScriptVar_t& s, T*, typename boost::enable_if_c<boost::is_base_of<CustomVar,T>::value, T>::type*) {
return *s.as<T>();
}
一些错误:
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(416): error C2059: Syntaxfehler: ')'
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(416): error C2143: Syntaxfehler: Es fehlt ',' vor ')'
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(416): error C2947: ">" wird erwartet, um template-argument-list abzubrechen. ">" wurde gefunden.
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(416): warning C4346: 'GetType<T>::value<T>::type': Abhängiger Name ist kein Typ
3> Präfix mit 'typename' zum Angeben eines Typs
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(416): error C2059: Syntaxfehler: ')'
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(421): error C2059: Syntaxfehler: ','
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(421): warning C4346: 'boost::is_base_of<CustomVar,T>::value': Abhängiger Name ist kein Typ
3> Präfix mit 'typename' zum Angeben eines Typs
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(421): error C2143: Syntaxfehler: Es fehlt ',' vor ')'
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(421): error C2143: Syntaxfehler: Es fehlt ';' vor '{'
3>c:usersalbert zeyerprogrammierungopenlieroxincludeCScriptableVars.h(423): error C2143: Syntaxfehler: Es fehlt ';' vor '}'
(顺便说一句,有没有办法用英语获得这些消息?我是MSVC的新手。例如,它说:">"应该取消模板参数列表,但找到了">"。)
错误消息大多是愚蠢或错误的。
为什么?我甚至不知道微软风投在什么方面挣扎。
我该如何解决它?
好的,找到问题了。enable_if_c<(GetType<T>::value < SVT_CUSTOM), T>
中较少的比较使编译器感到困惑,因为它不能真正知道value
是一个整数。
我把它改成了GetType<T>::value <= SVT_CUSTOM-1
,一切都很好。
相关文章:
- boost::进程间消息队列引发错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在cygwin中测试新的boost安装时出现cpp错误
- 错误"Could not find Boost"(缺少:上下文标头)
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- VS Code C++:不准确的系统包括路径错误(wchar.h,boost/lambda/lambda.hpp)
- 尝试将 boost::stacktrace 添加到 CMake 项目时出现构建错误
- 在 boost::qi 中使用过多的替代运算符会导致分段错误
- 使用boost::multiprecision cpp_int左移时出现超时错误
- 致命错误:找不到'boost/uuid/uuid.hpp'文件
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- 编译器错误boost :: asio ::占位符:: boost v1.69的错误
- C++链接错误(Boost线程)
- 错误:“boost::array”不是一种类型
- 开始使用boost-cpu_timer时,错误:“boost::timer::cpu_timer”尚未声明
- 编译错误-boost::numeric::ublas::coordinate_matrix
- Boost错误:Boost.文件系统V3及更高版本需要std::wstring支持
- 错误boost::文件系统没有名为string()的成员
- 错误:BOOST禁用线程
- 链接错误Boost.使用stlport作为标准库的Python