Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2006-03-22 11:35:00


Andy Little wrote:
> FYI I have discovered that in my useage of min the advice doesnt seem to help,
> my use being default construction of a temporary of type named max or min:
>>From one of my test files I currently ended up using the obvious workaround:
>
> // here boost::pqs::time::min is a typedef for a quantity of time in minutes
> #if ! defined (min)
> BOOST_CHECK(units_str( boost::pqs::time::min()) == "min");
> #else
> //use of min() looks like the macro so just create a variable
> boost::pqs::time::min min;
> BOOST_CHECK(units_str(min) == "min");
> #endif
>
> The only other option would seem to be to "save" the body of the min macro
> undefine it and then redefine it later, IOW not possible in practise AFAIK.
>
> If anyone has ideas what the preferred option is in this situation I would be
> interested to know?

See John's reply. Another option would be:

      typedef boost::pqs::time::min min_;
      BOOST_CHECK(units_str( min_()) == "min");

> ---------- Boost.Inspect and min max
>
> Inspect reports the above as a violation of boost guidelines of course, though I
> have attended to them. I dont know quite what else to do about it as the names
> are the recommended SI names. Ideally I would like to tell inspect to disable
> this "violation" here as I've attended to it etc.
>
> Inspect also reports use of min in comments as in the 2nd /3rd line below as a
> violation:
>
> #if defined (min)
> // some compilers use a min() macro
> // this causes a failure of useage of e.g my_stuff::min()
> // for other purposes
> #define DONT_USE_MIN_LIKE_CONSTRUCT
> #endif
>
>
> Finally Boost.Inspect reports use in strings as a violation:
>
> std::string my_min_str = "just a min()";
>
>
> I will try to come up with a patch for Boost.Inspect.

A patch would be welcome. Ideally, Inspect should use Wave and ignore
violations in comments and string literals.

Thanks!

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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