Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] Extending the library for a base class and all its derived - enable_if
From: Avi Kivity (avi_at_[hidden])
Date: 2014-04-24 10:00:24


On 04/23/2014 06:51 PM, Albert Yiamakis wrote:
>> I'm not sure if there is something special about your use-case that stops
>> method 2 from working. Perhaps you could take a look at the MFC support in
>> Boost.Range to see if this helps you add support for your classes.
>>
>> If you can provide some code that shows the classes you are trying to make
>> support ranges then I'd be happy to try and help.
>>
> A simple example:
>
> class Base {/* stuff */}; //it is in fact an abstract base class but
> shouldn't matter
>
> class Iterator {/* stuff */ }; //will be used to iterate - assume the
> default constructed represents end
>
> Now I 'd like all classes that derive from Base to model a Range. I have
> only been able to do this by adding the additional template parameter
> myself, then this is possible:
>
> namespace boost
> {
>
> template <typename C>
> struct range_iterator<C, typename enable_if<is_base_of<Base, C> >::type>
> { typedef Iterator type; };
>
> template<typename C>
> struct range_const_iterator<C, typename enable_if<is_base_of<Base, C>::type>
> { typedef Iterator type; };
> }
>

Would something like

   template <typename C>
   struct range_iterator<typename enable_if<is_base_of<Base, C>,
C>::type> { ... };

work?


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