mcandre / toys

code demos for newbies
https://github.com/mcandre/toys
30 stars 6 forks source link

C++ brace initialization #233

Closed mcandre closed 2 years ago

mcandre commented 3 years ago

Change more class, struct, and collection assignment initializers to sans-assign brace initializers.

Critically, applying a universal policy of brace initialization reduces the risk of known bugs associated with C++ parenthesis initialization. Particularly with shadowing and sensitive objects such as mutexes.

This change carries the benefit of better readability for non-primitive data structures (explicit types rather than auto). As well, the brace initializers visually distinguish between reassignment versus declaration, similar to how := works in Go.

For consistency, we can include primitives. For example, int x{ 5 };

Tasks:

Projects: