Special Interest Group on C++ @sigcpp.bsky.social · 31/05/2024Unwinding concept std::same_as up to std::integral_constant. Compilation of possible implementations from cppreference. Hope seeing it all together at once helps appreciate the behind-the-scenes. PS: read the code bottom to top; usable with no includes sigcpp.godbolt.org/z/nx6Y3sfvo #cpp #eduSky 101
Special Interest Group on C++ @sigcpp.bsky.social · 17/05/2024Delegate directly to the final ctor in a delegation chain, instead of delegating to a ctor which delegates to another, and so on. A bit more maintenance, but in general, can improves speed, size. E.g., S1() involves 4 ctors; but S2() involves only 2. sigcpp.godbolt.org/z/4e93ddd5x #cpp #eduSky 001
Special Interest Group on C++ @sigcpp.bsky.social · 15/05/2024C, C++ allow declaring struct var together w struct type. The syntax looks odd but makes sense if seen alongside var declaration for a primitive type (1). The syntax permits seemingly odd type qualifiers but the quals actually apply to the var not the type (2). sigcpp.godbolt.org/z/fvY64MMqT #cpp 001
Special Interest Group on C++ @sigcpp.bsky.social · 26/11/2023Logan Smith illustrates the pitfalls of using C-style casts in C++ code. Bottomline, instead of C-style cast, use an appropriate C++ cast such as `static_cast` and `dynamic_cast` depending on the situation. www.youtube.com/watch?v=SmlL... #cpp #cplusplus #programming #video 001
Special Interest Group on C++ @sigcpp.bsky.social · 11/09/2023Constants can help find certain errors at compile time instead of runtime: constexpr over const; const over non-const; macros/literals if you must. You don't always get this benefit but strive. E.g.: sigcpp.godbolt.org/z/sjd5vWrPn (Avoid "naked new" but another time) #cpp #cPlusPlus #programming 011
Special Interest Group on C++ @sigcpp.bsky.social · 16/07/2023If you need a std::string to be the reverse of another, you can: 1. Copy source and reverse the copy or 2. Create a new string inited from reverse iterators on source Approach 2 can be faster, and the new string can even be const. sigcpp.godbolt.org/z/9coKnYTTs #cpp #cplusplus #programming 101
Special Interest Group on C++ @sigcpp.bsky.social · 06/07/2023Use templates like these if you have many enum types and often convert them to integers. The 1-arg template converts an enum type to its underlying type. PS: std::to_integer converts only from std::byte and the integer type must be explicit. sigcpp.godbolt.org/z/4Waxaojrz #cpp #cplusplus 120