Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-06-26 07:57:30


 

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of Martin Bonner
| Sent: 26 June 2006 11:59
| To: boost_at_[hidden]
| Subject: Re: [boost] [test] test/included min max macro issue
|
| ----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();
?
| >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 preprocessor sees "max" and ")", and doesn't try to
| expand the macro.

Thanks, I am now better disambiguated - if at present macro vulnerable ;-(

Perhaps Tonto can add this to the Boost Guidelines ;-)

Paul

---
Paul A Bristow
Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB
+44 1539561830 & SMS, Mobile +44 7714 330204 & SMS
pbristow_at_[hidden]
 

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