Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2004-02-29 10:03:20


Eric Niebler wrote:

> Paul Mensonides wrote:
>
>> The only way to
>> "have-your-cake-and eat-it-too" in the presence of macros like min/max
>> is to
>> prevent them from expanding manually with
>> BOOST_PREVENT_MACRO_SUBSTITUTION.
>>
>> int main() {
>> using std::min;
>> min BOOST_PREVENT_MACRO_SUBSTITUTION(1, 2);
>> return 0;
>> }
>>
>> This yields ADL and local context (which includes std::min if necessary).
>
>
> Thanks, Paul. That's correct. boost::std_min is defined as follows:
>
> template< typename T >
> inline T const & std_min( T const & a, T const & b ) {
> using std::min;
> return min BOOST_PREVENT_MACRO_SUBSTITUTION ( a, b );
> }
>
> So a call to boost::std_min is essentially an unqualified call to min,
> with a using directive to pull in std::min. Since it's an unqualified
> call, ADL can also pull in additional overloads from different namespaces.

Maybe it's worth mentioning that it is only usefull for use in the
namespace boost. IIUC there is no lookup in the local namespace and
additional lookup in boost. I.e. it's not quite an unqualified call when
used outside boost.

Thomas


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