Testing existence of template type
Class TypeTraits tries to verify, whether its templated type contains
required types.
It works for non-template types, but I don't know, how to check for the
template one.
So is there any way to check for the existence of TestType::B?
#include <boost/utility/enable_if.hpp>
#include <boost/concept_check.hpp>
#include <iostream>
using namespace std;
template <typename T> struct TypeTautology { enum { value = true};};
template <class GP, typename Enable = void>
struct TypeTraitsImpl
{ enum { value = false }; };
template <class GP>
struct TypeTraitsImpl<
GP
,typename boost::enable_if<
TypeTautology<
typename GP::A//works ok, checks existence of A
//typename GP::B//compiles, but returns "test: 0"
//typename GP::template B//doesn't compile
//typename GP::template <class> B//doesn't compile
>
>::type
>
{ enum { value = true }; };
template <class GP> struct TypeTraits: public TypeTraitsImpl<GP, void>
{};
struct TestType
{
struct A {};
template <class PG> struct B {};
};
int main(int const, char const* [])
{
try
{
clog << "test: " << TypeTraits<TestType>::value << endl;
//Expected output:
//test: 1
return EXIT_SUCCESS;
}
catch (...){
cerr << "error" << endl;
}
exit(EXIT_FAILURE);
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]