以下问题给了我编译器错误,我不确定如何正确编写
struct FalseType { enum { value = false }; };
struct TrueType { enum { value = true }; };
template <typename T1, typename T2>
struct IsSame
{
typedef typename FalseType Result;
};
template <typename T>
struct IsSame<T,T>
{
typedef typename TrueType Result;
};
BOOST_STATIC_ASSERT( (IsSame< Foo::FooClass1 , Foo::FooClass1 >::Result::value) );
这个静态断言在使用时不应该失败,但不知何故,来自 CUDA 的编译器 NVCC 给了我以下错误:
error C2338: (IsSame< Foo::FooClass1 , Foo::FooClass1 >::Result::value)
我不知道该怎么做,所有其他 STATIC ASSERTIONS 都有效,但类型比较没有,那里有什么问题?错字?括号?
我无法让我的类型比较在 NVCC 下工作?
有任何想法吗?
似乎 MSVC(由 NVCC 路由到)在上述版本中也存在问题......嗯......
============= 编辑 ========================= 这里有一个在 MSVC 中不起作用的片段!
这个片段应该在 MSVC 中编译,但它没有,所以我假设编译器错误:
错误 C2118: 负下标 (WHHHHHYYYYYYY) 奇怪....
#include <iostream>
using namespace std;
struct FalseType { static const bool value = false ; };
struct TrueType { static const bool value = true ; };
template <typename T1, typename T2>
struct IsSame
{
typedef ::FalseType Result;
static const bool result = false;
};
template <typename T>
struct IsSame<T,T>
{
typedef ::TrueType Result;
static const bool result = true;
};
namespace OtherType{
struct Type1{};
};
template< typename _T> // Settings from below
struct Settings{
typedef _T myT;
typedef char static_assert_failed[ ((IsSame< _T,OtherType::Type1>::Result::value)) ? 1 : -1 ]; // USE HERE only ::result works, (BUT WHY)
};
int main(){
cout << (IsSame<OtherType::Type1,OtherType::Type1>::Result::value)<< endl;
}