More is_constant_evaluated tweaks/fixes.

This commit is contained in:
jzmaddock
2021-08-09 19:42:39 +01:00
parent ffb4cafce1
commit 5d67c38c10
5 changed files with 35 additions and 5 deletions

View File

@@ -4544,7 +4544,14 @@
when the current context is <code class="computeroutput"><span class="keyword">constexpr</span></code> when the current context is <code class="computeroutput"><span class="keyword">constexpr</span></code>
and false otherwise. This macro may be functional in C++14 onwards and false otherwise. This macro may be functional in C++14 onwards
if the compiler has a suitable intrinsic we recognise (MSVC/Clang/GCC if the compiler has a suitable intrinsic we recognise (MSVC/Clang/GCC
are currently supported). The macro always evaluates to <code class="computeroutput"><span class="keyword">false</span></code> on unsupported/old compilers. are currently supported).
</p>
<p>
Note that before using this macro, the program must include <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">type_traits</span><span class="special">&gt;</span></code>.
</p>
<p>
The macro always evaluates to <code class="computeroutput"><span class="keyword">false</span></code>
on unsupported/old compilers.
</p> </p>
</td> </td>
</tr> </tr>
@@ -4561,8 +4568,20 @@
The macro may be functional in C++14 onwards if the compiler has The macro may be functional in C++14 onwards if the compiler has
a suitable intrinsic, in particular this macro is functional for a suitable intrinsic, in particular this macro is functional for
gcc-6 and onwards as well as for compilers which have direct support gcc-6 and onwards as well as for compilers which have direct support
for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_constant_evaluated</span></code>. The macro for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_constant_evaluated</span></code>.
always evaluates to <code class="computeroutput"><span class="keyword">false</span></code> </p>
<p>
Note that before using this macro, the program must include <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">type_traits</span><span class="special">&gt;</span></code>.
</p>
<p>
Note that this macro may behave subtly different from <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_constant_evaluated</span><span class="special">()</span></code>
in that it may evaluate to <code class="computeroutput"><span class="keyword">true</span></code>
when code is evaluated in a non-constexpr context, but is none
the less evaluated at "compile time" as a result of program
optimisation.
</p>
<p>
The macro always evaluates to <code class="computeroutput"><span class="keyword">false</span></code>
on unsupported/old compilers. on unsupported/old compilers.
</p> </p>
</td> </td>

View File

@@ -996,7 +996,7 @@
</div> </div>
</div> </div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: August 08, 2021 at 18:21:47 GMT</small></p></td> <td align="left"><p><small>Last revised: August 09, 2021 at 18:40:57 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td> <td align="right"><div class="copyright-footer"></div></td>
</tr></table> </tr></table>
<hr> <hr>

View File

@@ -1088,10 +1088,20 @@ that are not yet supported by a particular compiler or library.
[[macro][Description]] [[macro][Description]]
[[`BOOST_IS_CONSTANT_EVALUATED()`][Evaluated to `true` when the current context is `constexpr` and false otherwise. [[`BOOST_IS_CONSTANT_EVALUATED()`][Evaluated to `true` when the current context is `constexpr` and false otherwise.
This macro may be functional in C++14 onwards if the compiler has a suitable intrinsic we recognise (MSVC/Clang/GCC are currently supported). This macro may be functional in C++14 onwards if the compiler has a suitable intrinsic we recognise (MSVC/Clang/GCC are currently supported).
Note that before using this macro, the program must include `<type_traits>`.
The macro always evaluates to `false` on unsupported/old compilers.]] The macro always evaluates to `false` on unsupported/old compilers.]]
[[`BOOST_IS_CONSTANT_EVALUATED_INT(integer-expression)`][Evaluates to `true` when `integer-expression` is `constexpr`. [[`BOOST_IS_CONSTANT_EVALUATED_INT(integer-expression)`][Evaluates to `true` when `integer-expression` is `constexpr`.
The macro may be functional in C++14 onwards if the compiler has a suitable intrinsic, in particular this macro is functional for gcc-6 and onwards The macro may be functional in C++14 onwards if the compiler has a suitable intrinsic, in particular this macro is functional for gcc-6 and onwards
as well as for compilers which have direct support for `std::is_constant_evaluated`. as well as for compilers which have direct support for `std::is_constant_evaluated`.
Note that before using this macro, the program must include `<type_traits>`.
Note that this macro may behave subtly different from `std::is_constant_evaluated()` in that it may evaluate to
`true` when code is evaluated in a non-constexpr context, but is none the less evaluated at "compile time" as a result
of program optimisation.
The macro always evaluates to `false` on unsupported/old compilers.]] The macro always evaluates to `false` on unsupported/old compilers.]]
[[BOOST_IS_CONSTANT_EVALUATED_VERSION][Evaluates to 0 if there is no support for this feature, 1 if `BOOST_IS_CONSTANT_EVALUATED_INT` is fully functional, and 2 if both [[BOOST_IS_CONSTANT_EVALUATED_VERSION][Evaluates to 0 if there is no support for this feature, 1 if `BOOST_IS_CONSTANT_EVALUATED_INT` is fully functional, and 2 if both
BOOST_IS_CONSTANT_EVALUATED_INT and BOOST_IS_CONSTANT_EVALUATED are fully functional.]] BOOST_IS_CONSTANT_EVALUATED_INT and BOOST_IS_CONSTANT_EVALUATED are fully functional.]]

View File

@@ -1094,7 +1094,7 @@ namespace std{ using ::type_info; }
# define BOOST_IS_CONSTANT_EVALUATED_INT(integer) BOOST_CONFIG_IS_CONST_EVALUATED_INT(integer) # define BOOST_IS_CONSTANT_EVALUATED_INT(integer) BOOST_CONFIG_IS_CONST_EVALUATED_INT(integer)
# define BOOST_IS_CONSTANT_EVALUATED_VERSION 1 # define BOOST_IS_CONSTANT_EVALUATED_VERSION 1
#else #else
# define BOOST_IS_CONSTANT_EVALUATED false # define BOOST_IS_CONSTANT_EVALUATED_INT(i) false
#endif #endif
#ifndef BOOST_IS_CONSTANT_EVALUATED_VERSION #ifndef BOOST_IS_CONSTANT_EVALUATED_VERSION

View File

@@ -7,6 +7,7 @@
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS #ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
#include <type_traits> #include <type_traits>
#include <cstdlib>
#if BOOST_IS_CONSTANT_EVALUATED_VERSION >= 2 #if BOOST_IS_CONSTANT_EVALUATED_VERSION >= 2
inline constexpr int factorial1(int i) inline constexpr int factorial1(int i)