GetFEM++  5.3
workaround.hpp
1 
2 // Copyright (c) 2002 David Abrahams
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 #ifndef WORKAROUND_DWA2002126_HPP
10 # define WORKAROUND_DWA2002126_HPP
11 
12 // Compiler/library version workaround macro
13 //
14 // Usage:
15 //
16 // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
17 // ... // workaround code here
18 // #endif
19 //
20 // When BOOST_STRICT_CONFIG is defined, expands to 0. Otherwise, the
21 // first argument must be undefined or expand to a numeric
22 // value. The above expands to:
23 //
24 // (BOOST_MSVC) != 0 && (BOOST_MSVC) <= 1200
25 //
26 // When used for workarounds that apply to the latest known version
27 // and all earlier versions of a compiler, the following convention
28 // should be observed:
29 //
30 // #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1301))
31 //
32 // The version number in this case corresponds to the last version in
33 // which the workaround was known to have been required. When
34 // BOOST_DETECT_OUTDATED_WORKAROUNDS is not the defined, the macro
35 // BOOST_TESTED_AT(x) expands to "!= 0", which effectively activates
36 // the workaround for any version of the compiler. When
37 // BOOST_DETECT_OUTDATED_WORKAROUNDS is defined, a compiler warning or
38 // error will be issued if the compiler version exceeds the argument
39 // to BOOST_TESTED_AT(). This can be used to locate workarounds which
40 // may be obsoleted by newer versions.
41 
42 # ifndef BOOST_STRICT_CONFIG
43 
44 # define BOOST_WORKAROUND(symbol, test) \
45  ((symbol != 0) && (1 % (( (symbol test) ) + 1)))
46 // ^ ^ ^ ^
47 // The extra level of parenthesis nesting above, along with the
48 // BOOST_OPEN_PAREN indirection below, is required to satisfy the
49 // broken preprocessor in MWCW 8.3 and earlier.
50 //
51 // The basic mechanism works as follows:
52 // (symbol test) + 1 => if (symbol test) then 2 else 1
53 // 1 % ((symbol test) + 1) => if (symbol test) then 1 else 0
54 //
55 // The complication with % is for cooperation with BOOST_TESTED_AT().
56 // When "test" is BOOST_TESTED_AT(x) and
57 // BOOST_DETECT_OUTDATED_WORKAROUNDS is #defined,
58 //
59 // symbol test => if (symbol <= x) then 1 else -1
60 // (symbol test) + 1 => if (symbol <= x) then 2 else 0
61 // 1 % ((symbol test) + 1) => if (symbol <= x) then 1 else divide-by-zero
62 //
63 
64 # ifdef BOOST_DETECT_OUTDATED_WORKAROUNDS
65 # define BOOST_OPEN_PAREN (
66 # define BOOST_TESTED_AT(value) > value) ?(-1): BOOST_OPEN_PAREN 1
67 # else
68 # define BOOST_TESTED_AT(value) != ((value)-(value))
69 # endif
70 
71 # else
72 
73 # define BOOST_WORKAROUND(symbol, test) 0
74 
75 # endif
76 
77 #endif // WORKAROUND_DWA2002126_HPP