1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
template < typename T, typename R, typename... A > struct has_dimensions
{
template < typename PTR_TO_MEN_FUN, PTR_TO_MEN_FUN > struct test_it ;
template < typename C >
static char strawman( test_it< R (C::*)(A...) const, &C::dimensions >* ) ;
typedef char two_chars[2] ; template < typename C > static two_chars& strawman(...) ;
constexpr static bool value = ( sizeof( strawman<T>(nullptr) ) == sizeof(char) ) ;
};
struct dimensionSet {} ;
struct A
{
dimensionSet dimensions() const ;
void dimensions(dimensionSet) ;
const dimensionSet& dimensions(int) const ;
void dimensions(char,int,int) ;
int dimensions(char,int,int) const ;
} ;
int main()
{
std::cout << std::boolalpha ;
// there is a dimensionSet A::dimensions() const
std::cout << has_dimensions<A,dimensionSet>::value << '\n' ; // true
// there is a void A::dimensions(dimensionSet) const
std::cout << has_dimensions<A,void,dimensionSet>::value << '\n' ; // false
// there is a dimensionSet A::dimensions(int,int) const
std::cout << has_dimensions<A,dimensionSet,int,int>::value << '\n' ; // false
// there is a int A::dimensions(char,int,int) const
std::cout << has_dimensions<A,int,char,int,int>::value << '\n' ; // true
// there is a const dimensionSet& A::dimensions(int) const
std::cout << has_dimensions<A,const dimensionSet&,int>::value << '\n' ; // true
// there is a void A::dimensions() const
std::cout << has_dimensions<A,void>::value << '\n' ; // false
}
|