
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Paul A Bristow Sent: 24 June 2006 14:34 To: boost@lists.boost.org 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@Pitechnology.com Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ, ENGLAND Tel: +44 (0)1223 203894