C++23: Bitwise Operations -- Sandor Dargo
While C++ is getting increasingly expressive with each new standard, we must not forget its origins. It is inherently a low-level language which operates close to the hardware level and allows operations that languages such as Javascript cannot even express.
A part of providing low-level functionalities is to be able to work on a byte or even on a bit level. In this post, we are going to see what related features C++23 brings or modifies.
C++23: Bitwise Operations
by Sandor Dargo
From the article:
constexpr std::bitsetTo be fair, we already covered this earlier last year in C++23: Even more constexpr. But as I’m using this feature to demonstrate the next one, I decided to mention it again.
P2417R2 extends the
constexprinterface ofstd::bitset. So far, only one of the constructors andoperator[]was marked asconstexpr. However, sincestd::stringcan beconstexpr, all the internals - and therefore the full API - ofstd::bitsetcan beconstexpr.If you’re unfamiliar with
std::bitset, it represents the object you pass in as a sequence of bits. You have to pass the number of bits as a non-type template argument.#include <bitset> #include <iostream> int main() { constexpr short i = 15; constexpr int numberOfBitsInInt = sizeof(i) * 8; std::cout << "i:" << i << ", i as binary: " << std::bitset<numberOfBitsInInt>(i) << '\n'; } /* i:15, i as binary: 0000000000001111 */It’s more capable than that, it also offers several ways to query the individual bits or set them.

A new episode of the series about SObjectizer and message passing:
Thanks to the powerful
This article explores the concept of class invariants in C++ and their significance in maintaining code integrity and abstraction. It highlights the difference between struct and class definitions and discusses the role of class invariants in guaranteeing the correctness of class objects. The article also touches upon the trade-offs between strong and weak invariants and provides insights into when to define a new class with proper invariants.
A new episode of the series about SObjectizer and message passing:
In this post, Victor talks about bringing compile times of the {fmt} library on par with the C standard I/O library (stdio).
Seastar announces that now that C++23 is available, they will support C++23 and C++20 (dropping support for C++17) in accordance with their support policy
In this software troubleshooting case, a customer experienced program crashes, and a detailed analysis of the code revealed several issues. The primary problem stemmed from lazy initialization of a widget list, leading to inconsistent vector states and potential crashes. Additionally, a multithreading issue was identified, highlighting the importance of thread-safety mechanisms in code that can be accessed concurrently.