Boost logo

Boost Users :

From: Hughes, James (jhughes_at_[hidden])
Date: 2007-08-21 09:28:14


 

                         

                
                Actually you can use only one Handler class and some
templated function overloads:
                
                template<class Base>
                class Hanlder
                {
                    template<class Derived>
                    void do_it(T const& t, typename boost::enable_if<
boost::is_base_of<Base, T> >::type*=0)
                    {
                      //do smth.
                    }
                
                   template<class Derived>
                   void do_it(boost::shared_ptr<T> t, typename
boost::enable_if< boost::is_base_of<Base, T> >::type*=0)
                   {
                     //do smth.
                   }
                
                   ....
                
                };
                 
                 
                
                Thanks Martin and Ovanes,
                 
                I think you have put me on the right track there. Much
appreciated.
                 
                James
                
                 
                 

        Just a quick addendum to this. I tried out a combination of the
two - using a BOOST_STATIC_ASSERT((boost::is_base_of<Base, T> >::value))
inside the do_it function described above, and found what I thought was
odd behaviour with is_base_of.

        The following excerpt shows the behaviour

        class A {};

        class B : public A {};

        typedef A C;

         BOOST_STATIC_ASSERT((boost::is_base_of<A,B> >::value)) //
this passes

         BOOST_STATIC_ASSERT((boost::is_base_of<A,C> >::value)) //
this fails

        I would expect both to pass, as is_base_of should return true
when both parameters are the same, and I thought that typedef did make
classes the same/equivalent

        
http://www.boost.org/doc/html/boost_typetraits/reference.html#boost_type
traits.is_base_of

        Is there something I am missing about typedef? Or is
boost::is_base_of unable to handles the aliasing?

        James

         

This message (including any attachments) contains confidential
and/or proprietary information intended only for the addressee.
Any unauthorized disclosure, copying, distribution or reliance on
the contents of this information is strictly prohibited and may
constitute a violation of law. If you are not the intended
recipient, please notify the sender immediately by responding to
this e-mail, and delete the message from your system. If you
have any questions about this e-mail please notify the sender
immediately.



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