Boost logo

Boost :

Subject: Re: [boost] [Range] begin/end ADL issues in C++0x range-based for
From: Michel MORIN (mimomorin_at_[hidden])
Date: 2010-12-21 08:13:57


Hi Jeffrey,

Jeffrey Lee Hellrung, Jr. wrote:
> Just to be clear, as you seemed to indicate something slightly different in
> another post: Do you propose to prevent boost::begin/end from being picked
> up by ADL; to prevent boost::fusion::begin/end from being picked up by ADL;
> or both...?

For boost::begin/end,
when I started this thread, I managed not to break existing codes
and so boost::begin/end can be picked by ADL.
But after I read your post in the Fusion thread,
I was beginning to think that cooperation between boost::begin/end and ADL is
not important and that solving the ambiguity call problem by ADL barrier is
a very simple and acceptable way.

For boost::fusion::begin/end,
when I started the Fusion thread, I also managed not to break existing codes
and so boost::fusion::begin/end can be picked by ADL.
But after I read your post in the Fusion thread, I agreed with your solution.

> Do either of these begin/end combinations actually *need* to be
> found via ADL (i.e., is that a desirable feature, regardless of it possibly
> breaking existing code)?

Now, my answer is no.

> Ranges adapted to work with Boost.Range (by
> defining range_begin/range_end) will generally have to be re-adapted to work
> with the range-based for loops, so I wouldn't think relying on
> boost::begin/end to be found via ADL to be too useful...

Agreed.

> Also, again to be clear: What are the tradeoffs between defining
> Boost.Fusion's begin/end in another namespace and bringing them into the
> boost::fusion namespace with a using declaration; and defining the data
> structures in another namespace and bringing them into the boost::fusion
> namespace with a using declaration; or both?

Oh, I remembered the ADL barrier idiom wrongly;
I was thinking only the former is the idiom (and I didn't know
that a using directive should be used in the former case).
Thank you for pointing this out, Jeffrey.

The correct idiom is:
 - Define Fusion's begin/end in another namespace and bringing them
   into the boost::fusion namespace with a using directive
   (not with a using declaration).
or
 - Define the data type in another namespace and bringing them
   into the boost::fusion namespace with a using declaration/directive.

The former prevents boost::fusion::begin/end from being picked up by ADL.
The latter prevents any ADL for the data type, except ADL triggered by
data type's template arguments and base classes.
I cannot tell which is more suitable. Do you have any idea?

Regards,
Michel


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