Tag: templates
15 posts
-
C++20 Concepts | Making Template Error Messages Readable
C++20 Concepts: clearer errors than SFINAE/enable_if—standard concepts, requires clauses, overloads, and practical C++20 examples.
-
Variadic Templates in C++: Parameter Packs, Pack Expansion, sizeof... and Fold Expressions
C++ variadic templates explained: parameter packs, where pack expansion is allowed, recursion vs fold expressions, empty packs, and the errors you will hit.
-
How <type_traits> Works: Type Queries, enable_if, void_t Detection and if constexpr
How C++ type traits actually work under the hood: SFINAE with enable_if, the void_t detection idiom, why if constexpr discards untaken branches, and how traits relate to C++20 concepts.
-
Tag Dispatching in C++: Overload Selection by Tag Types, vs if constexpr and Concepts
How tag dispatching picks a C++ overload at compile time with empty tag types, why iterator tags inherit from each other, and when if constexpr fits better.
-
C++ Template Argument Deduction
Function template argument deduction: decay rules, references, arrays, perfect forwarding, CTAD overview, and how to fix deduction failures.
-
C++ Templates for Beginners: Function and Class Templates, Instantiation and Why They Live in Headers
C++ templates from scratch: function and class templates, deduction, instantiation, typename, specialization, the header rule, and the errors beginners hit.
-
C++ Template Specialization: Full vs Partial, Why Overloads Beat Function Specializations, and ODR Traps
Full vs partial template specialization with real g++ errors: why function templates cannot be partially specialized, the Dimov/Abrahams surprise and ODR.
-
SFINAE in C++: enable_if, Expression SFINAE and When to Switch to Concepts
How SFINAE removes template overloads whose substitution fails, enable_if and decltype checks, void_t detection traits, and when C++20 concepts are better.
-
C++ Reference Collapsing: How T& && Becomes T&, and Why Forwarding References Depend on It
Reference collapsing in C++: the four rules, where they apply (templates, auto&&, typedefs, decltype), how std::forward uses them, and the bugs they cause.
-
C++ std::forward and Perfect Forwarding: How It Works and Where It Breaks
How std::forward preserves value category, why std::move in a template steals caller data, forwarding twice, and the arguments that cannot be forwarded.
-
C++ `if constexpr` | Compile-Time Branching in Templates
Use `if constexpr` to discard untaken branches during instantiation—unlike runtime `if`, avoiding ill-formed code in unused branches for templates.
-
C++ Function Overloading: Rules, Ambiguity, and Name
Why return type never disambiguates overloads, why float(10.0f) is not actually ambiguous between int and double, and how default arguments and const-qualified members interact with overload resolution.
-
How to Read C++ Template Error Messages: GCC, Clang Guide
Decode C++ template errors effectively. Learn to read compiler messages, understand SFINAE notes, and use C++20 concepts to shorten error output.
-
CRTP vs Virtual Functions: Static Polymorphism Without vtable Overhead
How CRTP gives C++ static polymorphism without a vtable, how it compares with virtual functions, the usual CRTP mistakes, and C++23 deducing this.
-
C++ CTAD and Deduction Guides: Class Template Argument Deduction (C++17)
How C++17 CTAD deduces class template arguments from constructors, when you need a user-defined deduction guide (iterator pairs, const char* to std::string), explicit guides, and the surprises with braces, copies and string literals.