Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-09-03 08:42:52


"Thorsten Ottosen" <nesotto_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote in message news:ur7pkurnp.fsf_at_boost-consulting.com...
> | "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
>
> | > Let me explain a little better this tricky situation. Since the Range
> | > concepts are described in terms of free-standing functions, we kind of
> | > loose the ability to say a class is a model of a Range concept if that
> | > class only has member functions in its interface.
> | >
> | > So since Collection has col.begin() and col.end() and not begin( col )
> | > and end( col ) it is not per se a model of any Range concept.
> | >
> | > Boost.Range then comes with an implementation of various Range
> | > concepts for *any* class that has begin() and end() members. So when
> | > this header with this implementation is included, all Collections
> | > model certain Range concepts; otherwise they do not.
> | >
> | > And since Ranges are complete decoupled from the class/member function
> | > idea, it does not make sense for classes to refine these concepts.
> | >
> | > hope it helps
> |
> | What we need is somthing like this:
> |
> | namespace boost { namespace range {
> |
> | namespace detail
> | {
> | template <class T>
> | typename range_iterator<T>::type begin(T& x)
> | {
> | return x.begin()
> | }
> |
> | template <class T>
> | typename range_iterator<T>::type adl_begin(T& x)
> | {
> | return begin(x); // will use ADL if a begin is defined
> | }
> | }
> |
> | template <class T>
> | typename range_iterator<T>::type begin(T& x)
> | {
> | return detail::adl_begin(x)
> | }
> |
> | }}
>
> apart from the adl stuff, it already is like that. Did you mean to
> put in the range namespace to avoid problems with classes in boost?

No, I mean so that the concept can be described in terms of
boost::range and Collection can become a refinement of Range.

> | Then you change the Range concept to require that
> | boost::range::begin(col) works.
>
> hm...yeah...one could perhaps state both syntaxes as part of the concept, eg
>
> Valid expressions
> ============
> begin( a )
> or
> a.begin()

No, you have to say boost::range::begin(col). Otherwise they could
make a.begin() valid but begin(a) invalid, and that would break
boost::range::begin.

> | Of course, Collection will only be a
> | refinement if there is no incorrect begin hanging around for that
> | type... so maybe this is fruitless.
>
> well, I agree that we have not got it complete right yet.
>
> perhaps the Range concept could specify
>
> Primary Template Behavior
> ==================
> return a.begin()
>
> ?

Wha???

What do primary templates have to do with this?

> And maybe we don't have to talk about collection as a refinement;
> maybe a new term is in order, like "act", sa in "all Collections may
> act as Ranges".

... provided that "..."

Or, we could say that certain refinements of Collection are also
refinements of Range.

-- 
Dave Abrahams
Boost Consulting
http://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