mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-16 17:47:02 +03:00
Add bit operations library.
This commit is contained in:
9
CPP20.md
9
CPP20.md
@@ -21,6 +21,7 @@ C++20 includes the following new library features:
|
||||
- [concepts library](#concepts-library)
|
||||
- [synchronized buffered outputstream](#synchronized-buffered-outputstream)
|
||||
- [std::span](#stdspan)
|
||||
- [bit operations](#bit-operations)
|
||||
|
||||
## C++20 Language Features
|
||||
|
||||
@@ -409,6 +410,14 @@ std::span<double, LENGTH_ELEMENTS> span2 = arr; // ERROR
|
||||
std::span<int, 1> span3 = arr; // ERROR
|
||||
```
|
||||
|
||||
### bit operations
|
||||
C++20 provides a new `<bit>` header which provides some bit operations including popcount.
|
||||
```c++
|
||||
std::popcount(0u); // 0
|
||||
std::popcount(1u); // 1
|
||||
std::popcount(0b1111'0000u); // 4
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -21,6 +21,7 @@ C++20 includes the following new library features:
|
||||
- [concepts library](#concepts-library)
|
||||
- [synchronized buffered outputstream](#synchronized-buffered-outputstream)
|
||||
- [std::span](#stdspan)
|
||||
- [bit operations](#bit-operations)
|
||||
|
||||
C++17 includes the following new language features:
|
||||
- [template argument deduction for class templates](#template-argument-deduction-for-class-templates)
|
||||
@@ -501,6 +502,14 @@ std::span<double, LENGTH_ELEMENTS> span2 = arr; // ERROR
|
||||
std::span<int, 1> span3 = arr; // ERROR
|
||||
```
|
||||
|
||||
### bit operations
|
||||
C++20 provides a new `<bit>` header which provides some bit operations including popcount.
|
||||
```c++
|
||||
std::popcount(0u); // 0
|
||||
std::popcount(1u); // 1
|
||||
std::popcount(0b1111'0000u); // 4
|
||||
```
|
||||
|
||||
## C++17 Language Features
|
||||
|
||||
### Template argument deduction for class templates
|
||||
|
||||
Reference in New Issue
Block a user