From Jason Turner
Watch on YouTube

Summary

In this episode, Jason explores a potential pitfall with Class Template Argument Deduction (CTAD) in C++17, specifically related to implicit conversions between container types. He demonstrates how returning a std::pair but receiving it as a std::tuple using CTAD can silently compile but result in significantly less efficient code. The issue stems from std::tuple having a non-explicit constructor that accepts std::pair and an associated deduction guide, allowing the implicit conversion which triples the assembly instructions. This example highlights why developers should be precise with their types and consider the 'almost always auto' approach to avoid such inefficiencies.

Resources

Tags