From Jason Turner
Watch on YouTube

Summary

This episode discusses a common performance issue with wrapper types like std::optional, std::variant, std::pair, std::tuple, std::any, and std::expected. Jason demonstrates how naively returning these types often creates unnecessary object constructions and moves, defeating return value optimization (RVO). He shows how most common patterns result in double constructions - first creating the value, then moving it into the wrapper - and explores various approaches to minimize this overhead, including in-place construction with emplace or std::in_place_t.

Resources

Tags