Boost logo

Boost Users :

Subject: Re: [Boost-users] [traits, fusion, mpl] Basic question about is_base_of and template ancestors
From: Roland Bock (rbock_at_[hidden])
Date: 2012-09-01 16:17:56


On 2012-08-30 15:10, Rindeberg Magnus wrote:
> #include <boost/type_traits.hpp>
> #include <boost/mpl/vector.hpp>
> #include <boost/fusion/include/mpl.hpp>
> #include <boost/fusion/container.hpp>
> #include <boost/fusion/include/at_key.hpp>
> #include <boost/fusion/include/for_each.hpp>
> #include <boost/fusion/include/filter_if.hpp>
>
> struct dostuff
> {
> template<typename T>
> void
> operator()(T const & x) const
> {
> // Do stuff here!
> }
> };
>
> template<class D>
> struct A
> {
> };
>
> template<class D, typename T>
> struct B
> {
> typedef T type;
> };
>
> struct derived_from_A : public A<derived_from_A>
> {
> };
>
> struct derived_from_B : public B<derived_from_B, int>
> {
> };
>
> typedef ::boost::mpl::vector<derived_from_A, derived_from_B>::type typelist_type;
>
> ::boost::fusion::result_of::as_set<typelist_type>::type typeset_;
>
> int
> main(int argc, char ** argv)
> {
> dostuff ds;
>
> // This seems to be working!
> ::boost::fusion::for_each(
> ::boost::fusion::filter_if
> < ::boost::is_base_of<A< ::boost::mpl::_>, ::boost::mpl::_>
> > (typeset_), ds);
>
> #if(0)
> // Don't know how to do this! Preferably I'd like to check for inheritance from B.
> // If that isn't possible I'll settle for "not inheriting from A".
> ::boost::fusion::for_each(
> ::boost::fusion::filter_if
> < ::boost::is_base_of<B< ::boost::mpl::_, WHAT_GOES_HERE? >, ::boost::mpl::_>
> > (typeset_), ds);
> #endif
> }
The "not" part is straight forward:

  ::boost::fusion::for_each(
      ::boost::fusion::filter_if
      < ::boost::mpl::not_< ::boost::is_base_of<A< ::boost::mpl::_>,
::boost::mpl::_> >
> (typeset_), ds);

I can't seem to wrap my head around an is_derived_from_b template, though.

But I wonder: Why do you want to add another parameter T here? Can't you
just define T inside derived_from_B?

Regards,

Roland


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