diff --git a/more/lib_guide.htm b/more/lib_guide.htm index c59a9de8cc..6d0ec5a42f 100644 --- a/more/lib_guide.htm +++ b/more/lib_guide.htm @@ -294,6 +294,44 @@ +
min()
and max()
+ macros. Some platform headers define min()
and max()
macros which
+ cause some common C++ constructs to fail to compile. Some simple tricks can protect your code
+ from inappropriate macro substitution:std::min()
or std::max()
:(std::min)(a,b)
if you do not require argument-dependent
+ look-up.boost::std_min(a,b)
if you do require argument-dependent look-up.
+ boost::std_min()
delegates to std::min()
.std::numeric_limits<int>::max()
, use
+ (std::numeric_limits<int>::max)()
instead.min()
or max()
member function,
+ instead to doing obj.min()
, use (obj.min)()
.min
+ or max
, then you must use the BOOST_PREVENT_MACRO_SUBSTITUTION
+ macro. Instead of writing int min() { return 0; }
you should write
+ int min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
This is true
+ regardless if the function is a free (namespace scope) function, a member function or a
+ static member function, and it applies for the function declaration as well as the
+ function definition.