From c918dbea71d13d29f1cc4f3598eb9f90205bc97e Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Sat, 22 Feb 2020 16:18:24 -0500 Subject: [PATCH] Add bit operations library. --- CPP20.md | 9 +++++++++ README.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/CPP20.md b/CPP20.md index d9bcd50..033fce0 100644 --- a/CPP20.md +++ b/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 span2 = arr; // ERROR std::span span3 = arr; // ERROR ``` +### bit operations +C++20 provides a new `` 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. diff --git a/README.md b/README.md index cfae902..c5bd5ea 100644 --- a/README.md +++ b/README.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++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 span2 = arr; // ERROR std::span span3 = arr; // ERROR ``` +### bit operations +C++20 provides a new `` 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