Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-06-26 06:58:30


----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Paul A Bristow
Sent: 24 June 2006 14:34 To: boost_at_[hidden]
Subject: Re: [boost] [test] test/included min max macro issue

> A further quick question on this problem.
>
> It is my custom (having a strong view that it aids readers -
> including me -
> of my programs) to write
>
> #include <limits>
> using std::numeric_limits;
>
> How do I avoid min/max macro problems when writing, for example,
>
> return numeric_limits<double>::max(); ?
>
> (numeric_limits<double>)::max(); ???
No.

>From the website:
>> > # If you want to call std::numeric_limits<int>::max(), use
>> > (std::numeric_limits<int>::max)() instead.>

The basic rule is that you must never have the (pp-)tokens "max" and "("
one after the other. If you do, the preprocessor will try to expand the
max macro.

The solution is to wrap the function name in parens, so what you would
write is:

        return (numeric_limits<double::max)();

That means the preprocessore sees "max" and ")", and doesn't try to
expand the macro.

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 203894

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