Loading ...
Sorry, an error occurred while loading the content.

min/max

Expand Messages
  • Mark Rodgers
    I have some code that uses std::min and std::max. Of course it doesn t work with MSVC. The work around I have used is #if defined(BOOST_MSVC) && _MSC_VER
    Message 1 of 3 , Jul 5, 2000
    • 0 Attachment
      I have some code that uses std::min and std::max. Of course it doesn't
      work with MSVC. The work around I have used is

      #if defined(BOOST_MSVC) && _MSC_VER <= 1200 && !defined(NOMINMAX)
      # undef min
      # undef max
      # define NOMINMAX
      namespace std
      {
      template<class T> inline const T &max(const T &x, const T &y)
      { return x < y ? y : x; }
      template<class T> inline const T &min(const T &x, const T &y)
      { return y < x ? y : x; }
      }
      #endif

      I'm working on theory that if NOMINMAX is defined, someone else is
      probably doing a similar workaround and I shouldn't attempt my fix.

      Two questions:

      1. Is my workaround correct, and has anyone got any better ideas?
      2. Is something along these lines something we should put in
      config.hpp or elsewhere?

      One possibility is that we could have a boost/algorithm.hpp that
      includes <algorithm> and then applies this fix. Similarly we could
      have boost/cstddef.hpp where the

      namespace std { using ::ptrdiff_t; using ::size_t; }

      fix could reside instead of in config.hpp.

      Thoughts?

      Mark
    • James Curran/MVP
      Actually, the problem isn t VC++ s libraries directly, but which defines min & max as macros and *must* maintain C compatibility for legal
      Message 2 of 3 , Jul 5, 2000
      • 0 Attachment
        Actually, the problem isn't VC++'s libraries directly, but <windows.h>
        which defines min & max as macros and *must* maintain C compatibility for
        "legal" reasons (i.e. if they drop support for C coding, making someone's C
        app no longer compilable, they'll be sued (again) for trying to drive a
        competitor out of the market)

        -----Original Message-----
        From: boost@egroups.com [mailto:boost@egroups.com]
        Date: Wed, 5 Jul 2000 12:17:56 +0200
        From: Saul Tamari <saul_tamari@...>
        Subject: RE: min/max

        Maybe you should try and buy a more conforming standard library from
        dinkumware (for VC++). It implements the min/max functions.
      • Thomas Plum
        ... Please ignore if unhelpful ... but many of these situations can be improved with standards-helper techniques like #include #undef min #undef
        Message 3 of 3 , Jul 18, 2000
        • 0 Attachment
          At 07:42 PM 7/5/00 -0400, you wrote:
          > Actually, the problem isn't VC++'s libraries directly, but <windows.h>
          >which defines min & max as macros ...

          Please ignore if unhelpful ... but many of these situations can be
          improved with "standards-helper" techniques like

          #include <windows.h>
          #undef min
          #undef max
          template < blah > T min( blah ) etc

          and the appropriate #if etc for feature tests ...



          -----------------------------------------------------------------------+

          Thomas Plum Plum Hall Inc, 3 Waihona Box 44610, Kamuela HI 96743 USA
          tplum@... TEL +1-808-882-1255 FAX +1-808-882-1556

          http://www.PlumHall.com
        Your message has been successfully submitted and would be delivered to recipients shortly.