Boost logo

Boost Users :

Subject: Re: [Boost-users] [traits, fusion, mpl] Basic question about is_base_of and template ancestors
From: Rindeberg Magnus (magnus.rindeberg_at_[hidden])
Date: 2012-09-04 04:18:18


Thanks Roland and Jeff!

I tried the not_ <> template and I don't know why I didn't get it to work the first time. Works fine now anyway!

Also tried the "nested_template" metafunction forwarding technique but never got that to work even though I did try some variations on the theme.

So I ended up with using the "automatic deduction of template parameters" approach (suggested by Jeff and shown below) and I'm quite happy with it since it improves readability compared to the "is_base_of" template (IMHO).

Thanks again!

// Magnus

struct yes_tag { char _[42]; };
struct no_tag { char _[1]; };

template< class T > T* declptr();

template< class T >
struct is_B_base_of
{
    template< class D, class U >
    static yes_tag test(B<D,U>*);
    static no_tag test(...);
    static bool const value = sizeof( test(declptr<T>()) ) == sizeof( yes_tag );
    typedef is_B_base_of type;
};

::boost::fusion::for_each(
    ::boost::fusion::filter_if< is_B_base_of< ::boost::mpl::_> >(typeset_), ds);


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net