|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-03-30 08:53:56
"Thorsten Ottosen" <nesotto_at_[hidden]> writes:
> Dear all,
>
> I'm going to change the ADL lookup hook of range functions.
>
> instead of the irritating
>
> void foo()
> {
> using namespace boost;
> begin(r);
> }
>
> we simply now say
>
> void foo()
> {
> boost::begin(r);
> }
>
> and get full ADL lookup. This changes the extension protocol
> to overiding these three functions:
>
> range_adl_begin()
> range_adl_end()
> range_adl_size()
>
> Any comments before I commit?
[I hope we've dropped "adl_" from the name by now ;-) ]
A scheme like this one has at least one advantage that we should be
sure to take advantage of: it allows us to reduce the number of
overloads required by conforming range classes. I've been working on
a similar scheme for an generalized Range concept ("Sequence" -- I
know it's used by the standard but how many suitable concept names
remain?), so here's some of my code:
---- namespace boost { namespace sequence { // Do not use directly, except to specialize. // Default implementation works for ordinary STL sequences. template <class Sequence> struct traits { typedef typename Sequence::iterator begin_iterator; typedef typename Sequence::iterator end_iterator; typedef typename Sequence::const_iterator begin_const_iterator; typedef typename Sequence::const_iterator end_const_iterator; }; template <class Sequence> struct begin_iterator { typedef typename sequence::traits< Sequence >::begin_iterator type; }; // Note: this partial specialization is important! template <class Sequence> struct begin_iterator<Sequence const> { typedef typename sequence::traits< Sequence >::begin_const_iterator type; }; template <class Sequence> typename begin_const_iterator<Sequence>::type begin(Sequence const& s) { return sequence_begin(s); } template <class Sequence> typename begin_iterator<Sequence>::type begin(Sequence& s) { return sequence_begin(s); } }} namespace my { struct range; // Note: no overload for Range const&. This is never // called directly, so it always receives an lvalue. template <class Range> typename begin_iterator<Sequence>::type sequence_begin(Range& s) { return ... // whatever } ... } -- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk