How to handle a transitive dependency conflict using Git submodules and CMake?

There are several approaches for detect and discard inclusion of the project, which has already be included in some other parts of the main project. Check project’s target existence The simplest pattern for single inclusion of subproject is checking existence of some subproject’s target: # When include ‘C’ subproject if(NOT TARGET library_C) add_subdirectory(C) endif() (Here … Read more

When is a `thread_local` global variable initialized?

The standard allows for this behavior, although it doesn’t guarantee it. From 3.7.2/2 [basic.stc.thread]: A variable with thread storage duration shall be initialized before its first odr-use (3.2) and, if constructed, shall be destroyed on thread exit. It’s also possible that the objects are constructed at some other time (e.g. on program startup), as “before … Read more

Using std::variant with recursion, without using boost::recursive_wrapper

boost::variant will heap allocate in order to have part of itself be recursively defined as itself. (It will also heap allocate in a number of other situations, uncertain how many) std::variant will not. std::variant refuses to heap allocate. There is no way to actually have a structure containing a possible variant of itself without a … Read more

Acquire/release semantics with 4 threads

You are thinking in terms of sequential consistency, the strongest (and default) memory order. If this memory order is used, all accesses to atomic variables constitute a total order, and the assertion indeed cannot be triggered. However, in this program, a weaker memory order is used (release stores and acquire loads). This means, by definition … Read more

Transparent Operator Functors

The transparent operator functors proposal is there as a way to have generalised functors that are located in <functional>. I personally believe the proposal itself has a very good example that would help illustrate the need for it. However I’ll go ahead and try to explain it as well. Suppose you have a function, a … Read more

What is the point of `std::make_optional`

One example of the difference is when you want (for whatever reason) to make an optional containing an optional: #include <optional> #include <type_traits> int main() { auto inner=std::make_optional(325); auto opt2=std::make_optional(inner); // makes std::optional<std::optional<int>> auto opt3=std::optional(inner); // just a copy of inner static_assert(std::is_same_v<decltype(opt2), std::optional<std::optional<int>>>); static_assert(std::is_same_v<decltype(opt3), std::optional<int>>); }