指定されたポインタ型がそうであるかどうかを確認するメタプログラムを実装しようとしてconst
いました。すなわち
is_const<TYPE*>::value
する必要がありますfalse
is_const<const TYPE*>::value
する必要がありますtrue
コードは次のとおりです。
template<class TYPE>
struct is_const
{
typedef char yes[3];
template<typename T>
struct Perform
{
static yes& check (const T*&);
static char check (T*&);
};
TYPE it;
enum { value = (sizeof(Perform<TYPE>::check(it)) == sizeof(yes)) };
};
また、コンパイラ エラー メッセージは次のとおりです。
In instantiation of ‘is_const<int*>’:
instantiated from here
error: no matching function for call to ‘is_const<int*>::Perform<int*>::check(int*&)’
note: candidates are: static char (& is_const<TYPE>::Perform<T>::check(const T*&))[3] [with T = int*, TYPE = int*]
note: static char is_const<TYPE>::Perform<T>::check(T*&) [with T = int*, TYPE = int*]
私の焦点はエラーメッセージに移りました。最後の行が表示された場合:
note: static char is_const<TYPE>::Perform<T>::check(T*&) [with T = int*, TYPE = int*]
実際に置換するT = int*
とTYPE = int*
、適切な関数 ( ) と一致するはずchar check()
です。ここで何がうまくいかないのか知りたいと思っています。