From: Timothy Baldwin on
On Oct 8, 12:11 am, "Kenneth 'Bessarion' Boyd" <zaim...(a)zaimoni.com>
wrote:

> Unfortunately, I haven't seen a good way to nonfatally compile-time
> test for the declaration of a (member) function. That would, at
> least, allow using a defaulted bool parameter to specialize the
> proposed class based on the presence of a Clone member function.

Using the decltype operator from C++0x allows a SFINAE condition if a
member function doesn't exist:

template <typename T> struct is_long {
static const bool result = false;
};

template <> struct is_long<long> {
static const bool result = true;
};

template <typename T> decltype(((T*)0)->clone(), long(0)) ctest(T* t);
char ctest(...);

struct A {
};

struct B {
B* clone();
};

#include <iostream>
int main() {
std::cout << is_long<decltype(ctest((A*)0))>::result << ' '
<< is_long<decltype(ctest((B*)0))>::result << '\n';
}


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

First  |  Prev  | 
Pages: 1 2 3
Prev: Help With TR1 regex_match()
Next: Is this correct C++?