Special Interest Group on C++
Teaching, learning, and practicing contemporary C++
#cpp #cplusplus #education #teaching #EduSky
Moderated by @smurthys.bsky.social
- Yes, it is late 2024, but C++23 is now officially an ISO standard. www.iso.org/standard/836... #cpp #cPlusPlus #standards #ISO
- std::string_view has 3 modifiers: remove_prefix, remove_suffix, swap. Working with immutable strings, unless you need a modifier, use const string view. (Anecdotally, most string views don't use modifiers.) en.cppreference.com/w/cpp/string/basic_… #cpp #cplusplus #programming
- [Not loaded yet]
- We may have to pass SV ref if a 3rd party function insists. In that case, a const SV object in our code would err if the function receives non-const ref. SV ref param can help if stack size is a concern: a ref. instead a pointer + size_t. Of course, const qualify the param to prevent side effects.
- "Modifier" is relative to the string_view object: alters string_view state, though the underlying string data itself remains unaltered. As always, it is good habit to const qualify objects we don't intend to modify. This is especially important if we hand a sv reference to someone else's function.
- @sidhin.bsky.social Just following up (mostly as clarification): > It’s still const reference right char s[] = "abc"; std::string_view sv(s); There are no const refs here. s is not modifiable via sv purely by virtue of SV API. However, sv itself is modifiable due to SV API.
- "Template Design with Policy Classes". A brief introduction to policy classes in C++. www.youtube.com/watch?v=23iz... #cpp #video #eduSky
- "Complete Guide to Class Template Argument Deduction". Excellent talk by Nina Ranns: -FTAD vs CTAD -CTAD and deduction guides -User-defined deduction guides -Pros & cons; Dos & Don'ts Well worth the hour for anyone writing class templates esp. as part of a library. #cpp #video youtu.be/c3R7aNf39o0
- Unwinding 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
- Possible implementation of std::same_as on cppreference defines the Same_Helper in a detail namespace, but that is flattened here☝️ for simplicity. Again, the code is compiled from cppreference. No claim made on it being best way to implement the concept/traits. en.cppreference.com/w/cpp/concep...
- Delegate 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
- C, 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
- Logan 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
- Constants 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
- If you're a CS student/faculty in India, Africa, or South America, and are interested in holding a SIGCPP event on your campus, please DM to discuss topics, schedules. #cpp #cplusplus #education #teaching #learning
- If 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
- Performance is implementation dependent but Approach 2 is most certainly faster due to avoiding initial copy. The std requires Aprch 2 to be linear in the distance between iterators and so it will be odd for Approach 2 to be slower. en.cppreference.com/w/cpp/string/basic_…
- Use 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
- C++23 std::to_underlying converts enum to underlying type, which you can then cast to other type. to_integer templates do all that w a uniform interface, but they may not always be the right match. As OP says use such templates to suit needs. en.cppreference.com/w/cpp/utility/to_un…
- Q: Why is the size of an empty class not zero? A: To ensure that every object has a unique memory address "Empty Objects", Slide 8. Johan Berg, SwedenCpp, June 15, 2023 More at: youtube.com/watch?v=vKDQxhyyMr8 #cpp #cplusplus #programming
- Return value optimization (RVO) in C++: flavors, guarantees, limitations, workarounds, and considerations. Examples and exercises included. sigcpp.github.io/2020/06/08/return-v… #cpp #cplusplus #rvo #programming #education #learning #edusky
- There's little reason to use C-strings (null-terminated byte sequences) in C++. Use std::string, std::string_view instead. C-string literals are OK but consider string, string_view literals instead: en.cppreference.com/w/cpp/string/basic_… #cpp #cplusplus #programming
- "Guidelines for processing immutable text" Conclusion of the 3-part series on working with immutable text data in C++ sigcpp.github.io/2020/04/20/guidelin… #cpp #cplusplus #programming #strings #text
- "Guidelines for processing immutable text" Conclusion of the 3-part series on working with immutable text data in C++ sigcpp.github.io/2020/04/20/guidelin… #cpp #cplusplus #programming #strings #text
- "Safely processing immutable text" Part 2 in the 3-part series on working with immutable text data in C++ sigcpp.github.io/2020/04/07/safely-p… #cpp #cplusplus #programming #strings #text
- "Efficiently processing immutable text" Part 1 in the 3-part series on managing immutable text data in C++ sigcpp.github.io/2020/04/03/efficien… #cpp #cplusplus #programming #strings #text
- "Exploring C-strings", an introduction to C-strings sigcpp.github.io/2020/03/30/explorin… #cpp #cplusplus #programming #cstrings #strings #text
- We begin our BlueSky presence by re-posting some past posts from our Twitter and Mastodon accounts. We expect to soon catch up and post new content directly from the BlueSky account.
- Hello and welcome to the BlueSky account for SIGCPP, the Special Interest Group on C++. We are also on Twitter and Mastodon. Twitter: twitter.com/sigcpp Mastodon: hachyderm.io/@sigcpp