Boost logo

Boost :

From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2006-03-03 16:08:45


Hello,

I've been using the Boost Range library a lot lately and felt the need for
some compile-time concept checks. They're pretty simple to write using the
Boost Concept Check library. So, I wrote concept checking classes for the
four range concepts mentioned in the documentation. To illustrate their
usage, the following checks if a type X models the ForwardRange concept.

function_requires<ForwardRangeConcept<X> >();

I've been checking the value access property of the range separately using
iterator concept checks on the range's iterator. So, for a
ForwardReadableRange ...

function_requires<ForwardRangeConcept<X> >();
function_requires<
    ReadableIteratorConcept<
        typename range_iterator<X>::type
>
>();

Implementing the concept checking classes is pretty straight forward using
the range documentation. As an example, here's my implementation for
BidierctionalRange.

template<typename X>
struct BidirectionalRangeConcept {
    typedef typename range_reverse_iterator<X>::type range_reverse_iterator;
    typedef typename range_const_reverse_iterator<X>::type
range_const_reverse_iterator;
    void constraints()
    {
        function_requires<ForwardRangeConcept<X> >();
        function_requires<
            boost_concepts::BidirectionalTraversalConcept<
                typename range_iterator<X>::type
>
>();
        i = rbegin(a);
        i = rend(a);
        const_constraints(a);
    }
    void const_constraints(const X& a)
    {
        ci = rbegin(a);
        ci = rend(a);
    }
    X a;
    range_reverse_iterator i;
    range_const_reverse_iterator ci;
};

Anyway, I hope there's enough interest to include concept checks like these
in the Boost Range library for a future release. I'd be glad to submit a
file containing my implementations. Please, let me know what you think!

Thanks,
 Daniel Walker


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk