struct
__true_type {};
struct __false_type {};
//bool to type
template <int _Is> struct __bool2type {
typedef __true_type _Ret;
};
template <> // icl supports both kinds of partial specialization
struct __bool2type<1> { typedef __true_type _Ret; };
// template <>
struct __bool2type<0> { typedef __false_type _Ret; };
//type to bool
template <class __bool_type>
struct __type2bool {
enum {_Ret = 1 };
};
template <class _Tp> struct _IsPtr { enum { _Ret = 0 }; };
// Partial specializations
template <class _Tp> struct _IsPtr<_Tp*> { enum { _Ret = 1 }; };
template <class _Tp> struct _IsPtrType {
enum { is_ptr = _IsPtr<_Tp> ::_Ret };
typedef typename __bool2type<is_ptr> ::_Ret _Type;
static _Type _Ret() { return _Type();}
};
// end of STL source
// Type checkers
void checkTrueType(const __true_type& ) {}
void checkFalseType(const __false_type& ) {}
template<class T>
void isPtrType(T) {
checkTrueType(_IsPtrType<T*> ::_Ret());
}
template<class T>
void notPtrType(T) {
checkFalseType(_IsPtrType<T*> ::_Ret());
}
int main()
{
char* it = 0 ;
isPtrType(it);
notPtrType(it); // Compile-time error
return 0 ;
}
// output: (Intel C++ Compiler 9.1)
// E:dhb's DocumentsVC 6 Projects
// STL_CompileTime_TypeCheckCheckIterator.cpp(52):
// error: no suitable user-defined conversion
// from "_IsPtrType<char **>::_Type"
// to "const __false_type" exists
// checkFalseType(_IsPtrType<T*>::_Ret());
// ^
// detected during instantiation of
// "void notPtrType(T) [with T=char *]"
struct __false_type {};
//bool to type
template <int _Is> struct __bool2type {
typedef __true_type _Ret;
};
template <> // icl supports both kinds of partial specialization
struct __bool2type<1> { typedef __true_type _Ret; };
// template <>
struct __bool2type<0> { typedef __false_type _Ret; };
//type to bool
template <class __bool_type>
struct __type2bool {
enum {_Ret = 1 };
};
template <class _Tp> struct _IsPtr { enum { _Ret = 0 }; };
// Partial specializations
template <class _Tp> struct _IsPtr<_Tp*> { enum { _Ret = 1 }; };
template <class _Tp> struct _IsPtrType {
enum { is_ptr = _IsPtr<_Tp> ::_Ret };
typedef typename __bool2type<is_ptr> ::_Ret _Type;
static _Type _Ret() { return _Type();}
};
// end of STL source
// Type checkers
void checkTrueType(const __true_type& ) {}
void checkFalseType(const __false_type& ) {}
template<class T>
void isPtrType(T) {
checkTrueType(_IsPtrType<T*> ::_Ret());
}
template<class T>
void notPtrType(T) {
checkFalseType(_IsPtrType<T*> ::_Ret());
}
int main()
{
char* it = 0 ;
isPtrType(it);
notPtrType(it); // Compile-time error
return 0 ;
}
// output: (Intel C++ Compiler 9.1)
// E:dhb's DocumentsVC 6 Projects
// STL_CompileTime_TypeCheckCheckIterator.cpp(52):
// error: no suitable user-defined conversion
// from "_IsPtrType<char **>::_Type"
// to "const __false_type" exists
// checkFalseType(_IsPtrType<T*>::_Ret());
// ^
// detected during instantiation of
// "void notPtrType(T) [with T=char *]"