Boost logo

Boost :

Subject: Re: [boost] [Range] Boost and N2930?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-07-31 12:19:57


Beman Dawes wrote:
> N2930, Range-Based For Loop Wording (Without Concepts), provides begin()
> and end() non-member function templates for standard library types. It
> also provides general range access non-member templates:
>
> // 24.7 range access [iterator.range]
> template<typename C> auto begin(C& c) -> decltype(c.begin());
> template<typename C> auto begin(const C& c) -> decltype(c.begin());
> template<typename C> auto end(C& c) -> decltype(c.end());
> template<typename C> auto end(const C& c) -> decltype(c.end());
> template<typename T, size_t N> T* begin(T (&array)[N]);
> template<typename T, size_t N> T* end(T (&array)[N]);
>
> (Until the official WG21 site gets updated, you can see a copy of n2930
> at http://mysite.verizon.net/beman/n2930.html)
>
> Should Boost.Range and/or RangeEx be modified and/or extended in light
> of N2930?

Such functions are not defined very differently in Boost.Range.
I believe they are defined like this:

template<typename C>
typename range_iterator<C>::type begin(C&);

template<typename C>
typename range_iterator<const C>::type begin(const C&);

with
template<typename C>
struct range_iterator
{
     typedef typename C::iterator type;
};

template<typename C>
struct range_iterator<const C>
{
     typedef typename C::const_iterator type;
};

Is it really worth it to remove dependency over iterator and
const_iterator member types?

I guess it would be possible to change the definition of range_iterator
to use decltype((*(C*)0).begin()) otherwise.


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