SFINAE — substitution failure versus a compilation error
SFINAE allows a template overload to be discarded when argument substitution produces an invalid type or expression in the immediate context. It does not hide arbitrary template errors.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
SFINAE allows a template overload to be discarded when argument substitution produces an invalid type or expression in the immediate context. It does not hide arbitrary template errors.
Correct sorting requires a comparator that defines a strict weak ordering. Binary search requires a range partitioned for the relevant condition; sorting the entire range is sufficient but not always necessary.
A C++ string stores elements, not ready-made user-visible characters. Learn the distinction between UTF-8 code units, Unicode code points, and grapheme clusters, and understand the roles of std::u8string and a u8 string literal.
Templates describe families of functions or types, while concepts state requirements on template arguments. The declaration template<Integer T> introduces a type parameter T constrained by Integer<T>, checked during compilation rather than at runtime.
Tests compare program behavior with expectations, while assertions express conditions that should hold. Learn property-based testing, idempotence, and a deterministic test corpus, plus the distinction between assert, static_assert, and checks that remain active when NDEBUG is defined.
std::chrono separates durations, time points, and calendar dates. Learn the %F and %R formats and the distinction between a fixed UTC offset and a named time zone.
Translation units let parts of a program be translated separately. Linkage determines name identity across declarations, while the ODR constrains the number and form of definitions. Distinguishing these concepts helps you split code correctly between headers and implementation files.
Type conversion adapts an expression to a required type. Learn implicit conversions, explicit static_cast conversions, integral promotions, and discarding a value with a cast to void.
The C++ type system defines the types of objects, references, functions, and expressions, together with permitted operations and conversions. Typing is static: auto deduces a type but does not let a variable change type later. Implicit conversions may be allowed even when they risk losing information.
A user-defined literal combines a numeric, character, or string literal with a custom suffix. Its literal operator turns that spelling into a value, such as an object representing a distance.
The categories lvalue, prvalue, and xvalue describe expressions, not kinds of variables. Learn their glvalue and rvalue groupings and how they relate to references, overload selection, and std::move, which does not itself transfer resources.
A variable lets a program store and refer to data of a particular type. Learn declarations, initialization, assignment, the roles of auto and const, and the distinction between a name's scope and an object's lifetime.
The objects std::execution::seq, std::execution::par, std::execution::par_unseq and std::execution::unseq specify how an algorithm is permitted to execute. They do not guarantee a speedup; choosing a policy also changes the requirements on functions that process elements.
The INT_MAX macro from <climits> specifies the largest int value for an implementation. Use it instead of hard-coding the limit, and check it before incrementing a value to avoid overflow.
Constants of type std::memory_order control synchronization and ordering for atomic operations. Learn how relaxed, release, acquire, acq_rel, and seq_cst differ, and how an atomic flag can safely publish ordinary data.
std::ignore is a standard-library object used with std::tie to skip selected elements during tuple assignment. It lets you store the values you need in existing variables without creating a dummy variable for the skipped element.
`+hardPass` uses unary `+` to convert a captureless, non-generic lambda to a function pointer. It does not perform addition.
Learn how C++23 selects class-specific `operator new` and `operator delete` overloads and why the paired global calls must receive the same alignment value.
The `[]` declarator forms a built-in array type. The bound can be part of the array type, but array syntax in a function parameter does not pass a length.
AoS stores complete records side by side, whereas SoA groups each field into its own array. Which layout fits depends on how the program accesses the data.
`assert` checks an internal program assumption at runtime. Defining `NDEBUG` can disable the check without evaluating its condition; it does not affect `static_assert`.
Distinguish an object’s storage duration and lifetime from any separate allocations made by its members, such as storage for a `std::string`’s characters.
Choose a data layout based on what the program actually reads. AoS groups the fields of a record; SoA groups values of the same field across records.
Capture a threshold by value so the predicate keeps using it even when the original variable changes.