mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-16 17:47:02 +03:00
Added std::is_constant_evaluated.
This commit is contained in:
12
CPP20.md
12
CPP20.md
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user