Added std::is_constant_evaluated.

This commit is contained in:
Anthony Calandra
2020-02-22 16:51:40 -05:00
parent 47733e4e29
commit 6b11829603
2 changed files with 24 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ C++20 includes the following new library features:
- [std::span](#stdspan)
- [bit operations](#bit-operations)
- [math constants](#math-constants)
- [std::is_constant_evaluated](#stdis_constant_evaluated)
## C++20 Language Features
@@ -426,6 +427,17 @@ std::numbers::pi; // 3.14159...
std::numbers::e; // 2.71828...
```
### std::is_constant_evaluated
Predicate function which is truthy when it is called in a compile-time context.
```c++
constexpr bool is_compile_time() {
return std::is_constant_evaluated();
}
constexpr bool a = is_compile_time(); // true
bool b = is_compile_time(); // false
```
## Acknowledgements
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
* [C++ Rvalue References Explained](http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics.