forked from boostorg/config
Add helper macro BOOST_IF_CONSTEXPR.
This commit is contained in:
@ -978,6 +978,7 @@ provide compliant C++17 support.
|
|||||||
[table
|
[table
|
||||||
[[Macro ][ Description ]]
|
[[Macro ][ Description ]]
|
||||||
[[`BOOST_INLINE_VARIABLE`][This macro expands to `inline` on compilers that support C++17 inline variables and to nothing otherwise. Users may need to check for `BOOST_NO_CXX17_INLINE_VARIABLES` for further adjustments to the code.]]
|
[[`BOOST_INLINE_VARIABLE`][This macro expands to `inline` on compilers that support C++17 inline variables and to nothing otherwise. Users may need to check for `BOOST_NO_CXX17_INLINE_VARIABLES` for further adjustments to the code.]]
|
||||||
|
[[`BOOST_IF_CONSTEXPR`][Expands to `if constexpr` when supported, or `if` otherwise.]]
|
||||||
]
|
]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@ -1002,6 +1002,14 @@ namespace std{ using ::type_info; }
|
|||||||
#else
|
#else
|
||||||
#define BOOST_INLINE_VARIABLE
|
#define BOOST_INLINE_VARIABLE
|
||||||
#endif
|
#endif
|
||||||
|
//
|
||||||
|
// C++17 if constexpr
|
||||||
|
//
|
||||||
|
#if !defined(BOOST_NO_CXX17_IF_CONSTEXPR)
|
||||||
|
# define BOOST_IF_CONSTEXPR if constexpr
|
||||||
|
#else
|
||||||
|
# define BOOST_IF_CONSTEXPR if
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unused variable/typedef workarounds:
|
// Unused variable/typedef workarounds:
|
||||||
|
@ -51,6 +51,12 @@ struct no_unique
|
|||||||
BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b;
|
BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <bool b>
|
||||||
|
struct trait
|
||||||
|
{
|
||||||
|
enum { value = b };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -66,6 +72,11 @@ int main()
|
|||||||
always_throw();
|
always_throw();
|
||||||
nodiscard_struct s;
|
nodiscard_struct s;
|
||||||
no_unique no_un;
|
no_unique no_un;
|
||||||
|
|
||||||
|
BOOST_IF_CONSTEXPR(trait<true>::value)
|
||||||
|
{
|
||||||
|
result += 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(int)
|
catch(int)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user