1 // Copyright David Abrahams 2002. Permission to copy, use,
2 // modify, sell and distribute this software is granted provided this
3 // copyright notice appears in all copies. This software is provided
4 // "as is" without express or implied warranty, and with no claim as
5 // to its suitability for any purpose.
6 #ifndef WORKAROUND_DWA2002126_HPP
7 # define WORKAROUND_DWA2002126_HPP
9 // Compiler/library version workaround macro
13 // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
14 // ... // workaround code here
17 // When BOOST_STRICT_CONFIG is defined, expands to 0. Otherwise, the
18 // first argument must be undefined or expand to a numeric
19 // value. The above expands to:
21 // (BOOST_MSVC) != 0 && (BOOST_MSVC) <= 1200
23 // When used for workarounds that apply to the latest known version
24 // and all earlier versions of a compiler, the following convention
25 // should be observed:
27 // #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1301))
29 // The version number in this case corresponds to the last version in
30 // which the workaround was known to have been required. When
31 // BOOST_DETECT_OUTDATED_WORKAROUNDS is not the defined, the macro
32 // BOOST_TESTED_AT(x) expands to "!= 0", which effectively activates
33 // the workaround for any version of the compiler. When
34 // BOOST_DETECT_OUTDATED_WORKAROUNDS is defined, a compiler warning or
35 // error will be issued if the compiler version exceeds the argument
36 // to BOOST_TESTED_AT(). This can be used to locate workarounds which
37 // may be obsoleted by newer versions.
39 # ifndef BOOST_STRICT_CONFIG
41 # define BOOST_WORKAROUND(symbol, test) \
42 ((symbol != 0) && (1 % (( (symbol test) ) + 1)))
44 // The extra level of parenthesis nesting above, along with the
45 // BOOST_OPEN_PAREN indirection below, is required to satisfy the
46 // broken preprocessor in MWCW 8.3 and earlier.
48 // The basic mechanism works as follows:
49 // (symbol test) + 1 => if (symbol test) then 2 else 1
50 // 1 % ((symbol test) + 1) => if (symbol test) then 1 else 0
52 // The complication with % is for cooperation with BOOST_TESTED_AT().
53 // When "test" is BOOST_TESTED_AT(x) and
54 // BOOST_DETECT_OUTDATED_WORKAROUNDS is #defined,
56 // symbol test => if (symbol <= x) then 1 else -1
57 // (symbol test) + 1 => if (symbol <= x) then 2 else 0
58 // 1 % ((symbol test) + 1) => if (symbol <= x) then 1 else divide-by-zero
61 # ifdef BOOST_DETECT_OUTDATED_WORKAROUNDS
62 # define BOOST_OPEN_PAREN (
63 # define BOOST_TESTED_AT(value) > value) ?(-1): BOOST_OPEN_PAREN 1
65 # define BOOST_TESTED_AT(value) != ((value)-(value))
70 # define BOOST_WORKAROUND(symbol, test) 0
74 #endif // WORKAROUND_DWA2002126_HPP