Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2002-04-22 23:38:12


> "Paul Mensonides" <pmenso57_at_[hidden]> wrote in message
> news:002001c1ea70$f5494120$7772e50c_at_c161550a...
> > I posted this at comp.std.c++, but I don't think it went
> through--I'm not trying
> > to 'cross-post'. :)
>
> [snip]
>
> You may want to look for past threads on clc++m. Look for those that
> have "reiterated question" in the body. Basically you can figure out
> whether a class has a member or not, but the mechanics rely on a
> combination of obscure features.
>
> > This compiles and words as desired on Comeau C++, but I'm wondering
> if it is
> > *legal* C++. I'm using it to create an unbounded (theoretically)
> multi-method
> > dispatcher, but I need to check where a type has that member
> function. If not,
> > then I need to revert (at compile-time) to using dynamic_cast.
>
> Cool idea. I wanted to use members discovery for different purposes
> (composite types as well), but in the end I decided to give up. Too
> complicated.
>
>
> Andrei

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 Mensonides


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