In C++, = default and {} are not the same constructor
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
Daniel Lemire shows that in C++ an empty default constructor written as = default and one written as {} can differ sharply in speed. The first keeps the type trivial, while {} is user-provided and makes it non-trivial. In his span-and-box loop benchmark, GCC 15.2 and 16.2 run the = default version at about 7.75–8.04 ns per span versus 1.73 ns for {}. GCC 14.3 and clang 21 show no gap. The test covers one workload on one Xeon CPU.