Category: C++
-
PayloadOffset_t: A small type design challenge
Recently, I had to make a relatively small design decision – which type to use for a small range of values. As usual in C++, there were a number of […] The post PayloadOffset_t: A small type design challenge appeared first on Simplify C++!.
-
Core Guidelines are not Rules
There is a difference between guidelines and rules. Boiling down guidelines to one-sentence rules has drawbacks that make your code harder to understand. The famous quote by Captain Barbossa from […] The post Core Guidelines are not Rules appeare…
-
Why we probably shouldn’t have constexpr conditional operator
The idea I had a great idea. We have constexpr if, but no constexpr conditional operator. Time for a proposal? Since we can do stuff like this: Wouldn’t it be cool if we could also do My motivation was that I had a std::variant visitor that was identical for all types except one. So instead … Continue reading Why we probably shouldn’t have constexpr conditional operator
-
Microsoft C++ versions explained
Microsoft has five different version numbers to think about when it comes to C++. Here’s an attempt to explain what they all mean. Visual Studio versions What most people will see first is the Visual Studio release year. You’ll download Visual Studio 2022, Visual Studio 2019 etc. These however also have a more normal major.minor … Continue reading Microsoft C++ versions explained
-
isValid()? Establish invariants and avoid zombie objects
When classes have an “isValid” method or similar, the code using them often is less clear and harder to maintain. If possible, validity should be an invariant that can not […] The post isValid()? Establish invariants and avoid zombie …
-
The Perils of Multi-Phase Construction
I’ve never really been a fan of C#’s object initializer syntax. Yes, it’s a little more convenient to write but it has a big downside which is it forces you to make your types mutable by default. Okay, that’s a bit strong, it doesn’t force you to do an…
-
The Perils of Multi-Phase Construction
I’ve never really been a fan of C#’s object initializer syntax. Yes, it’s a little more convenient to write but it has a big downside which is it forces you to make your types mutable by default. Okay, that’s a bit strong, it doesn’t force you to do an…
-
Guaranteed Copy Elision Does Not Elide Copies
This post is also available at the Microsoft Visual C++ Team Blog C++17 merged in a paper called Guaranteed copy elision through simplified value categories. The changes mandate that no copies or moves take place in some situations where they were pre…
-
Spaceship Operator
You write a class. It has a bunch of member data. At some point, you realise that you need to be able to compare objects of this type. You sigh and resign yourself to writing six operator overloads for every type of comparison you need to make. Afterwa…
-
Super Simple Named Boolean Parameters
Quite often we come across interfaces with multiple boolean parameters, like this: cake make_cake (bool with_dairy, bool chocolate_sauce, bool poison); A call to this function might look like: auto c = make_cake(true, true, false); Unfortunately,…
-
Function Template Partial Ordering: Worked Examples
C++ function overloading rules are complex. C++ template rules are complex. Put the two together, and you unfortunately do not get something simple; you get a hideous monster of standardese which requires great patience and knowledge to overcome. Howev…
-
std::accumulate vs. std::reduce
std::accumulate has been a part of the standard library since C++98. It provides a way to fold a binary operation (such as addition) over an iterator range, resulting in a single value. std::reduce was added in C++17 and looks remarkably similar. This …
-
No more pointers
This was an April Fools post. One of the major changes at the most recent C++ standards meeting in Jacksonville was the decision to deprecate raw pointers in C++20, moving to remove them completely in C++23. This came as a surprise to many, with a lot…
-
emBO++ 2018 Trip Report
emBO++ is a conference focused on C++ on embedded systems in Bochum, Germany. This was it’s second year of operation, but the first that I’ve been along to. It was a great conference, so I’m writing a short report to hopefully convince more of you to a…
-
Do compilers take inline as a hint?
If you’ve spent any time in C or C++ communities online, you’ve probably seen someone say this: inline used to be a hint for compilers to inline the definition, but no compilers actually take that into account any more. You shouldn’t believe ever…
-
Passing overload sets to functions
Passing functions to functions is becoming increasingly prevalent in C++. With common advice being to prefer algorithms to loops, new library features like std::visit, lambdas being incrementally beefed up12 and C++ function programming talks consisten…
-
Catch Up
It’s been just over six years since I first announced Catch to the world as a brand new C++ test framework! In that time it has matured to the point that it can take on the heavyweights – while still staying true to its original goals of being light…
-
Catch Up
It’s been just over six years since I first announced Catch to the world as a brand new C++ test framework! In that time it has matured to the point that it can take on the heavyweights – while still staying true to its original goals of being light…
-
How to write Boost.Python type converters
Boost.Python [1] makes it possible to write C++ that “feels” like Python. The library is powerful and sometimes subtle. This is as compared with the Python C API, where the experience is very far removed from writing Python code.
Part of making C++ feel more like Python is allowing …
-
How to write Boost.Python type converters
Boost.Python [1] makes it possible to write C++ that “feels” like Python. The library is powerful and sometimes subtle. This is as compared with the Python C API, where the experience is very far removed from writing Python code.
Part of making C++ feel more like Python is allowing …
-
Capturing lvalue references in C++11 lambdas
Recently the question “what is the type of an lvalue reference when captured by reference in a C++11 lambda?” was asked. It turns out that it’s a reference to whatever the original reference was too. This is just like taking a reference to an existing …
-
Capturing lvalue references in C++11 lambdas
Recently the question “what is the type of an lvalue reference when captured by reference in a C++11 lambda?” was asked. It turns out that it’s a reference to whatever the original reference was too. This is just like taking a reference to an existing …