Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-09-04 02:40:04


Eric Niebler <eric_at_[hidden]> writes:

> Oh, wait. Are you referring to something like this:
>
> namespace super_private {
> template<typename T>
> some-return-type begin_impl(T &t) {
> return begin(t);
> }
> }
>
> namespace boost {
> template<typename T>
> some-return-type begin(T &t) {
> return super_private::begin_impl(t);
> }
> }
>
> The unqualified call to begin() in namespace super_private will not find
> the one in namespace boost, hence no infinite recursion. But this
> doesn't quite work because if type T has boost as an associated
> namespace, it *will* consider the begin() in namespace boost, and we're
> back to infinite recursion.

Something like the following is what I had in mind. Your thing is
probably almost equivalent, but a little harder to read, and doesn't
support a default implementation:

  namespace boost {

  namespace default_ // where the default implementation of begin
  { // lives.
    template <class S>
    typename range_result_iterator<S>::type
    begin(S& s)
    { return s.begin() }
  }

  namespace adl // where begin can be called without qualification
  { // thus avoiding infinite recursion
    template <class S>
    typename range_result_iterator<S>::type
    begin_(S& x)
    {
        using default_::begin;
        return begin(x);
    }
  }

  template <class T>
  typename range_result_iterator<S>::type
  begin(S& x)
  {
      return adl::begin_(x);
  }

  template <class T>
  typename range_result_iterator<S const>::type
  begin(S const& x)
  {
      return adl::begin_(x);
  }

  }
  
> Regardless, it was gcc's interpretation of name-lookup that put the
> kibosh on unqualified calls to begin() and end().

Right, now I remember. What a shame.

-- 
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