|
Boost : |
Subject: Re: [boost] [concept] concept-based overloading (N2081)
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-05-27 15:57:13
On Thu, May 27, 2010 at 1:48 PM, Jeffrey Lee Hellrung, Jr.
<jhellrung_at_[hidden]> wrote:
> On 5/27/2010 10:38 AM, Lorenzo Caminiti wrote:
>> N2081 briefly mentions this can be done in C++ using SFINAE, etc. I
>> think I could use `enable_if` if I had some sort of
>> `is_input_iterator` metafunction... Please just point me to the
>> documentation if this has already been addressed there.
>>
> Do you mean the iterator_category / iterator_traversal metafunctions in
> boost/iterator/iterator_traits.hpp ?
>
> http://www.boost.org/libs/iterator/doc/iterator_traits.html
>
> template< class Iterator >
> typename boost::disable_if<
> boost::is_convertible<
> typename boost::iterator_traversal< Iterator >::type,
> boost::bidirectional_traversal_tag
> >
>>::type
> advance(...) { ... } // for IncrementableIterator's
>
> template< class Iterator >
> typename boost::enable_if<
> boost::is_convertible<
> typename boost::iterator_traversal< Iterator >::type,
> boost::bidirectional_traversal_tag
> >
>>::type
> advance(...) { ... } // for BidirectionalIterator's
>
> I think the primary way to currently effect "concept-based" overloading is
> via tags or similar metafunction-based methods. There do exist
> introspection techniques, though, such as proto's can_be_called or
> is_incrementable in boost/detail/, so it is possible to overload based on
> (some) syntactic properties.
>
> Is that what you're looking for?
Essentially, the above code from Jeff got the job done for what I
needed. I used `enabled_if` and tagging.
Also thanks to everyone else for the very informative comments.
-- Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk