mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 02:24:35 +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)
|
- [std::span](#stdspan)
|
||||||
- [bit operations](#bit-operations)
|
- [bit operations](#bit-operations)
|
||||||
- [math constants](#math-constants)
|
- [math constants](#math-constants)
|
||||||
|
- [std::is_constant_evaluated](#stdis_constant_evaluated)
|
||||||
|
|
||||||
## C++20 Language Features
|
## C++20 Language Features
|
||||||
|
|
||||||
@@ -426,6 +427,17 @@ std::numbers::pi; // 3.14159...
|
|||||||
std::numbers::e; // 2.71828...
|
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
|
## Acknowledgements
|
||||||
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
|
* [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.
|
* [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.
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -23,6 +23,7 @@ C++20 includes the following new library features:
|
|||||||
- [std::span](#stdspan)
|
- [std::span](#stdspan)
|
||||||
- [bit operations](#bit-operations)
|
- [bit operations](#bit-operations)
|
||||||
- [math constants](#math-constants)
|
- [math constants](#math-constants)
|
||||||
|
- [std::is_constant_evaluated](#stdis_constant_evaluated)
|
||||||
|
|
||||||
C++17 includes the following new language features:
|
C++17 includes the following new language features:
|
||||||
- [template argument deduction for class templates](#template-argument-deduction-for-class-templates)
|
- [template argument deduction for class templates](#template-argument-deduction-for-class-templates)
|
||||||
@@ -518,6 +519,17 @@ std::numbers::pi; // 3.14159...
|
|||||||
std::numbers::e; // 2.71828...
|
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
|
||||||
|
```
|
||||||
|
|
||||||
## C++17 Language Features
|
## C++17 Language Features
|
||||||
|
|
||||||
### Template argument deduction for class templates
|
### Template argument deduction for class templates
|
||||||
|
|||||||
Reference in New Issue
Block a user