次の問題でコンパイラ エラーが発生し、正しく記述する方法がわかりません
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)
どうすればいいのかわかりません。他のすべての静的アサーションは機能しますが、型比較は機能しません。何が問題なのですか? 打ち間違え?ブラケット?
NVCC で型比較が機能しませんか?
何か案は?
MSVC (NVCC によってルーティングされる) にも上記のバージョンで問題があるようです....うーん...
============= 編集 ======================== MSVC で動作しないスニペットをここに!
この抜粋は MSVC でコンパイルする必要がありますが、そうではないため、コンパイラのバグを想定しています。
エラー C2118: 負の添字 (WHHHHHYYYYYY) がおかしい....
#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;
}