Daily bit(e) of C++

Daily bit(e) of C++ is a Substack focused on C++ programming, offering insights into modern C++ practices, standard library improvements, language features introduced in recent standards, and common programming patterns and problems. It covers both basic and advanced topics, aiming to enhance the understanding and application of C++ for its readers.

Modern C++ Features C++ Standard Library Programming Patterns Software Development Tools Language-Specific Patterns and Practices Code Optimization and Efficiency Error Handling Memory Management C++ Standard Improvements Integration with C APIs

The hottest Substack posts of Daily bit(e) of C++

And their main takeaways
78 implied HN points 20 Jan 24
  1. Dealing with assumptions in programming can be risky, especially in C++ where a violated assumption can lead to undefined behavior.
  2. Proper engineering practices like good unit test coverage and sanitizers can help catch bugs, but sanitizers may not detect all issues, particularly at the library level.
  3. Using the hardened mode of standard library implementations like stdlibc++ and libc++ can provide safety features against specific attacks and checks without affecting ABI, enhancing development experience.
Get a weekly roundup of the best Substack posts, by hacker news affinity:
39 implied HN points 24 Jan 24
  1. C++23 introduces std::out_ptr and std::inout_ptr for interoperability between smart pointers and C-style APIs.
  2. In C APIs, the (re-)allocating function can accept handles as T** or void**.
  3. The results of std::out_ptr and std::inout_ptr should be temporary and not outlive the current expression.
39 implied HN points 23 Jan 24
  1. std::bind_front is a simpler alternative to std::bind, introduced in C++20.
  2. Unlike std::bind, std::bind_front only allows binding of leading arguments.
  3. std::bind_front doesn't have some limitations that std::bind has.
39 implied HN points 22 Jan 24
  1. C++11 introduced scope enumerations.
  2. Enumerators of scoped enumerations are named constants within the scope of the enumeration, preventing namespace pollution.
  3. Scoped enumerations are not implicitly convertible to the underlying type.
39 implied HN points 10 Jan 24
  1. std::string is a container for storing null-terminated narrow character strings in C++.
  2. std::string provides functionality similar to std::vector and maintains null-termination invariant.
  3. It also offers convenience methods like find, starts/ends_with, contains, and substr.
19 implied HN points 11 Feb 24
  1. The std::find_end algorithm in C++ helps find the last instance of a subrange in a range.
  2. It operates similarly to std::search but returns the last instance instead of the first.
  3. This algorithm can be useful when you need to search for the final occurrence of a specific sequence in a larger set of data.
19 implied HN points 10 Feb 24
  1. decltype(auto) can be useful when auto type-deduction causes issues, especially with function result types.
  2. It's worth considering decltype(auto) as it follows decltype rules to determine types, offering a potentially better solution.
  3. To explore decltype(auto) further, you can check out Compiler Explorer for practical examples and implementation details.
19 implied HN points 09 Feb 24
  1. The algorithm std::reverse_copy in C++ copies a bidirectional range in reverse order into an output range.
  2. Using std::reverse_copy is often more straightforward than using std::copy with reverse iterators.
  3. Subscribe to Daily bit(e) of C++ for more insights and support the author's work.
19 implied HN points 07 Feb 24
  1. std::move and std::move_backward are complementary algorithms to std::copy and std::copy_backward, moving elements between ranges.
  2. These algorithms will resort to copying when dealing with immovable types.
  3. The variants provide efficient ways to manipulate elements within C++ ranges.
19 implied HN points 05 Feb 24
  1. The algorithm std::search_n finds the first instance of n consecutive elements matching a specified value in C++.
  2. The range version conveniently returns the range representing the n consecutive elements.
  3. Both versions of std::search_n support a custom comparator.
19 implied HN points 03 Feb 24
  1. std::latch is a simple synchronization primitive in C++20.
  2. Latches are initialized with a count, can be decreased atomically, and used for blocking until the count is zero.
  3. std::latch can be a useful tool for synchronization in C++ programming.
19 implied HN points 02 Feb 24
  1. std::byteswap is a C++23 utility that changes the byte order in a variable.
  2. Combining std::byteswap with std::endian provides a solution for handling data with different byte orders.
  3. Compiler Explorer can be used to explore and understand code implementations.
19 implied HN points 01 Feb 24
  1. Name lookup for dependent names in templated classes is crucial.
  2. Non-dependent names are looked up before template instantiation.
  3. Understanding how name lookup works can prevent unexpected behavior in C++ templates.
19 implied HN points 31 Jan 24
  1. The std::merge algorithm merges two sorted ranges into a third range.
  2. The merged elements maintain their order in a stable manner.
  3. Equal elements from the first range appear before elements from the second range.
19 implied HN points 30 Jan 24
  1. std::declval helps obtain lvalue references for types without default constructors
  2. Be careful using decltype with types that can't be default constructed
  3. std::declval can only be used in unevaluated contexts like decltype
19 implied HN points 29 Jan 24
  1. Use decltype to get the type of an entity or expression
  2. Surround an entity with parentheses to treat it as an expression
  3. Stay updated on C++ concepts with regular posts from the source
19 implied HN points 26 Jan 24
  1. offsetof only works for standard layout types
  2. pointer to a standard layout type and its first member are pointer-interconvertible
  3. standard layout union with standard layout structs allows access to common initial sequence through non-active members
19 implied HN points 25 Jan 24
  1. The std::find_first_of algorithm in C++ finds the left-most matching element in a range.
  2. Both ranges in std::find_first_of are not ordered, resulting in quadratic complexity.
  3. Subscribe to receive more posts and support the author's work.
19 implied HN points 21 Jan 24
  1. Unscoped enumerations introduce named constants into a scope.
  2. The compiler automatically selects the backing type, unless explicitly specified.
  3. C++11 Scoped Enumerations are generally preferred over unscoped ones.
19 implied HN points 19 Jan 24
  1. std::stack is a container adapter for stack/LIFO functionality in C++.
  2. It helps in avoiding recursion and can be used for implementing undo functionality.
  3. Subscribe to receive more C++ insights and support the author's work.
19 implied HN points 18 Jan 24
  1. C++20 introduced synchronized streams.
  2. Multiple synchronized streams can be used to write to a single destination stream without introducing data races.
  3. All accesses to a stream should be through a synchronized stream to avoid interleaving.
19 implied HN points 17 Jan 24
  1. The 'Rule of zero' is based on the single responsibility principle.
  2. A class should not have special member functions unless it's managing ownership.
  3. Following the 'Rule of zero' can help in avoiding complexity in class design.
19 implied HN points 11 Jan 24
  1. C++23 introduces std::print and std::println as alternatives to std::format for outputting to stdio FILE descriptors.
  2. Both std::print and std::println default to outputting to standard output (stdout).
  3. Subscribe to receive more Daily bit(e) of C++ posts and support the author's work.
117 implied HN points 01 Apr 23
  1. In C++, variables can have unique memory addresses, even if initialized with the value of another variable.
  2. Constants in C++ can be either const or constexpr, with constexpr variables initialized using constant expressions.
  3. In C++, the lifetime of objects is tied to their location in the code, specifically to the scope.
98 implied HN points 03 Jun 23
  1. Iterators provide an abstraction layer for containers and different types allow for specific operations such as forward, backward, or random access iteration.
  2. Algorithms in the standard library provide efficient ways to perform common operations on containers like sorting, copying, and looking up elements.
  3. Views help avoid unnecessary data copies by allowing for lazy evaluation of operations on ranges, providing a more efficient way to chain operations.
78 implied HN points 13 Jul 23
  1. std::sort is a well-known sorting algorithm in C++.
  2. It sorts elements by default in non-descending order.
  3. C++17 and C++20 standards introduced improvements, like a parallel variant and range version.