Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-12-03 18:42:47


Peter Dimov wrote:
> Eric Niebler wrote:
>
>>Templates don't "foil lookup in the global namespace." They merely
>>require that the overload has been seen already. I have no problem
>>requiring users of broken compilers to put the overload where
>>BOOST_FOREACH can find it. Users of non-broken compilers can put the
>>overload in an associated namespace and be happy.
>
> That's what I do. Non-ADL compilers usually don't have two-phase lookup, so
> it balances out.
>

Actually, I just found a compromise: make the global namespace an
associated namespace. Now, the recommended procedure for customizing
BOOST_FOREACH is to define a function:

inline boost::mpl::true_ *
boost_foreach_has_cheap_copy(your_type*, boost::foreach::tag)
{
     return 0;
}

This can go in an associated namespace of your_type /or/ for maximum
portability in the global namespace. (boost::foreach::tag is a typedef
for an enum_at_global_scope_with_a_really_long_ugly_name.) This allows
for a very simple implementation of BOOST_FOREACH that even VC6 seems
happy with.

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