この非常に漠然としたタイトルで申し訳ありませんが、説明するのは非常に難しいです。
私が立ち往生しているエラーはこれです、私はそれが何を意味するのか分かりません:
carray.h:176:エラー:'typename Carray <T、Allocator> :: is_iterator' names'template <class T、class Allocator> template <class I、bool check> struct Carray <T、Allocator> :: is_iterator'、タイプではありません
何かがイテレーターであるかどうかを検出し、正しいオーバーロードを使用するためのこのスニペットがあります(http://stackoverflow.com/questions/6050441/why-does-this-constructor-overload-resolve-incorrectly)。これはコンパイルします:
template<class T> class Carray {
private:
// uses SFINAE to determine if the passed in type is indeed an iterator
template<class It>
class is_iterator_impl {
private:
typedef char yes[1];
typedef char no[2];
template<class C>
static yes& _test(typename C::iterator_category*);
template<class>
static no& _test(...);
public:
static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
};
template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
template<class It> struct is_iterator<It*, false> { typedef void type; };
template<class It> struct is_iterator<It, false> { };
public:
template<class It>
Carray(It first, It last, typename is_iterator<It>::type *dummy = 0) {
// create array from 2 iterators
}
};
ここで、実装を宣言から分離したかったので、これを試しましたが、エラーが発生しました。
template<class T> class Carray {
private:
// uses SFINAE to determine if the passed in type is indeed an iterator
template<class It> class is_iterator_impl;
template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
template<class It> struct is_iterator<It*, false> { typedef void type; };
template<class It> struct is_iterator<It, false> { };
public:
template<class It> Carray(It first, It last, typename is_iterator<It>::type *dummy = 0);
};
template<class T>
template<class It>
Carray<T>::Carray(It first, It last, typename Carray<T>::is_iterator<It>::type *dummy) {
// create array from 2 iterators - ERROR IN THIS DEFINITION
}
template<class T>
template<class It>
class Carray<T>::is_iterator_impl {
private:
typedef char yes[1];
typedef char no[2];
template<class C>
static yes& _test(typename C::iterator_category*);
template<class>
static no& _test(...);
public:
static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
};
g++4.5.5を使用しています。