Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-04-23 08:01:13


----- Original Message -----
From: "Paul Mensonides" <pmenso57_at_[hidden]>

> We already solved this one over there Andrei! Maybe you didn't see
it. It
> relies on the template 'type deduction' failing. I came up with an
is_enum
> because I didn't know that one existed here at Boost at the time.
>From there,
> several people came up with some interesting things. This checks
whether a give
> type has a nested type named 'nested':
>
> template<class T> class has_key_nested {
> private:
> template<class U> static small_t check(typename U::nested*);
> template<class U> static large_t check(...);
> public:
> static const bool value = sizeof(check<T>(0)) ==
sizeof(small_t);
> };
>
> Now that I look at it, 14.8.2/2 bullet 3, sub-bullet 3 appears to say
it is
> legal, but I don't speak fluent ISO. :)

Paul,

It's legal, and I already used your trick to implement an is_class which
works on incomplete and noncopyable types with a conforming compiler
(see the CVS). Compiler support for this idiom, however, is spotty at
best. None of the officially-released compilers I am testing with
support it, for example.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk