2011-08-19 92 views
6

これは自明です。私は配布ソートを実装しようとしているし、MSVCコンパイラがクラッシュしています。私のSFINAEでメンバー関数を検出する特定のケースのようですが、関数にindexertを渡してもhas_get_indexを置き換えても表示されません。残りのインデクサーのオーバーロードを削除しても、それは起こりません。ソート可能なメンバーがgetIndex() constのメンバーである場合、問題は残ります。C1001:コンパイラで内部エラーが発生しました

1>test.cpp(34): fatal error C1001: An internal error has occurred in the compiler. 
1> (compiler file 'msc1.cpp', line 1420) 
1> To work around this problem, try simplifying or changing the program near the locations listed above. 

最小限のテストケース(なし "の上に記載されている場所は" ありません)されています。おそらく、あなたが意図したものではありません

#include <vector> 
#include <iterator> 
#include <type_traits> 

#ifndef HAS_MEM_FUNC //SFINAE (or maybe it is?) 
#define HAS_MEM_FUNC(name, func)          \ 
    template<typename T>            \ 
    struct name {              \ 
     typedef char yes[1];           \ 
     typedef char no [2];           \ 
     template <typename C> static yes& test(typename C::func) ; \ 
     template <typename C> static no& test(...);     \ 
     static bool const value = sizeof(test<T>(0)) == sizeof(yes); \ 
    } 
#endif 
HAS_MEM_FUNC(has_get_index,getIndex); 

//default indexer undefined 
template <class T> 
double indexer(...); 
//indexer for objects that have a "T::getIndex() const" member 
template <class T> 
double indexer(const typename std::enable_if<has_get_index<T>::value,T>::type& b) { 
    return b.getIndex(); 
}; 

template<class indexert> 
void function(indexert indexeri) 
{} 

struct sortable {}; 

int main() { 
    function(indexer<sortable>); //line 34 
} 
+1

http://connect.microsoft.com/ –

+0

Hm、あなたのエラーについてはわかりませんが、[pretty printer](http://louisdx.github.com/cxx-prettyprint/)にバグを提出してください。メンバ型とメンバ関数の両方のSFINAE特性、それを見ることができます。 –

+0

@Kerrekかなりのプリンタコードは "T :: const_iterator T :: begin/end()const"が存在するかどうかを検出するためのSFINAE型の特性を要求しますが、実際には "begin"と "end"というメンバをチェックします。具体的な関数ではありません...それは、libが部分的にスタックオーバーフローの答えを一緒にコピーしたことを示しています。 –

答えて

5

この:typename

template <typename C> static yes& test(typename C::func) ; 

あなたが言いますコンパイラはC::funcとなります。実際には関数になりますが、パラメータ宣言に関数名を入れても意味がありません。

typenameの代わりにtypeofを使用する予定ですか?

+2

コンパイラがクラッシュするのを止めます。マイクロソフトブー! –

関連する問題