Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-07-15 13:18:40


Andrey Melnikov <melnikov_at_[hidden]> writes:

> What about
>
> BOOST_WORKAROUND_BEFORE(GCC, 3,2,3)
> BOOST_WORKAROUND_AFTER(GCC, 3,2,3)
> BOOST_WORKAROUND_STARTING_FROM(GCC, 3,2,3)
>
> and other plain English words instead of syntactic tricks with putting <
> signs as macro parameters? Is it going to be more verbose and cryptic
> than using macrost with < ?

Why do you call that a "syntactic trick?" The operator gets used in
the macro expansion and ends up being used by the preprocessor with
the obvious semantics. Just about every other token in

  BOOST_WORKAROUND(GCC, >, 3,2,3)

is trickier than the ">".

The desire to spell out comparison operations as english words seems
akin to the desire to embed compiler/ide versions in macro names.

> Here are real life examples from intrusive_ptr.hpp and mem_fn.hpp:
>
> #elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__,
> BOOST_TESTED_AT(0x3003))
>
> #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) &&
> !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
>
> How we are going to transform the latter?
>
> #if !BOOST_WORKAROUND_BEFORE(MSVC, 8,0,0) &&
> !BOOST_WORKAROUND_BEFORE(MWERKS, 9,0,1)

Ick.

  #if !BOOST_WORKAROUND(MSVC, <=, 7,0,0) && !BOOST_WORKAROUND(MWERKS, <, 9,0,0)

> Can we get rid of these "!" signs?
>
> !a && !b
>
> looks too verbose to me.

You can always write:

  #if !(BOOST_WORKAROUND(MSVC, <=, 7,0,0) || BOOST_WORKAROUND(MWERKS, <, 9,0,0))

but it's not much better.

> But of course
>
> !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
>
> isn't equivalent to
>
> BOOST_WORKAROUND(__MWERKS__, >= 0x3200)

The ! signs come from people having a desire to put the non-workaround
code first, but that IMO is a misguided effort, since it begins to get
nasty once you have more than one workaround:

  #if !BOOST_WORKAROUND( xxx ) && !BOOST_WORKAROUND( yyy ) && !BOOST_WORKAROUND( zzz )
     ..
  #elif BOOST_WORKAROUND( xxx )
    ...
  #elif BOOST_WORKAROUND( yyy )
    ...
  #elif BOOST_WORKAROUND( zzz )
    ...
  #endif

It's so much simpler as:

  #if BOOST_WORKAROUND( xxx )
    ...
  #elif BOOST_WORKAROUND( yyy )
    ...
  #elif BOOST_WORKAROUND( zzz )
    ...
  #else
    ...
  #endif

-- 
Dave Abrahams
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