#cpp #cplusplus #cpp26 #simdPerson 1: What are you dressed up as?
Person 2: A harp
Person 1: Aren't you small for a harp?
Person 2: Are you calling me a lyre?
🥁
Order-dependent bugs have got to be the hardest to even realize existing. Especially in a C++ compiler.
If writing tests for our little software is a pain, the pain of writing tests for a C++ compiler has to be a million times. And that's not even counting the testing needed for different means to accomplish the same thing. Order dependency only makes things harder from there.
We cannot ever thank enough the FOSS implementers. 🙇♂️ 🫡 🙏
C++20 introduced a significant change to lambdas without capture. The autogenerated unique type is now default-constructible and copy (and move) assignable.
While the previous behaviour made sense for lambdas with captures and conceptually (each lambda is inherently an instance of its autogenerated type), it also made lambdas awkward to use as arguments to generic code.
Compiler Explorer link: https://compiler-explorer.com/z/TY4oqYccc
int main() { // Using a function object struct Cmp { bool operator()(int l, int r) const { return l < r; } } cmp; std::map<int,int,Cmp> a; // OK std::map<int,int,decltype(cmp)> b; // OK a = b; // OK // Same logic using a lambda auto lcmp = [](int l, int r) { return l < r; }; std::map<int,int,decltype(lcmp)> c(lcmp); // OK // pre-C++20 we have to copy-construct the comparator std::map<int,int,decltype(lcmp)> d; // Wouldn't compile pre-C++20 // pre-C++20 delctype(lcmp) isn't default constructible c = d; // Wouldn't compile pre-C++20 // pre-C++20 decltype(lcmp) isn't copy-assignable }
Wish #cpp allowed concept definitions in class scope, not just namespace scope. DRY, better encapsulate class, reduce litter outside class.
E.g., if a class has many functions w "strict bool" parameter:
- (a) works, not DRY
- (b) DRY but concept visible in client along with class
//a: repeat w each function
template<typename B> requires std::same_as<B, bool>
void f(B b);
//b: once
template<typename B>
concept strict_bool = std::same_as<B, bool>;
void f(strict_bool auto b); //succinct
From “The Irrationals”
🤯