Re: Type traits and accessibility
On 14 Apr., 13:18, Mathias Gaunard <loufo...@gmail.com> wrote:
On 13 avr, 22:57, Daniel Kr?gler <daniel.krueg...@googlemail.com>
wrote:
std::is_constructible
needs compiler-support
Not necessarily.
You could use SFINAE to check whether the expressions that defines
is_contructible's value are well-formed.
Nope, SFINAE is *not* access-tolerant. Just try
template<class T>
struct HasStaticFoo {
typedef char No;
typedef char(&Yes)[2];
template<class U, class = decltype(U::foo())>
static Yes test(void*);
template<class>
static No test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(Yes);
};
struct S {
static void foo();
};
struct D {};
class X {
static void foo();
};
static_assert(HasStaticFoo<S>::value, "Ouch");
static_assert(!HasStaticFoo<D>::value, "Ouch");
static_assert(!HasStaticFoo<X>::value, "Ouch");
int main() {}
with a recent C++0x capable compiler and you will notice
that the error for X is *not* related to a violation of static_assert.
is_constructible and is_convertible are traits that *require*
compiler support, because they were intended to cope with
access restrictions. I haven't tested recent implementations
but I would expect that most of them still behave like normal
SFINAE-based realizations, which - strictly speaking - are
non-conforming, but the easiest to do for the moment.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]