C++ CPP study materials
C++ CPP study resources

C++ CPP: C++ templates, callable objects, streams and exceptions

C++ CPP · Work through your exam, one topic at a time.

All guide sections

C++ templates, callable objects, streams and exceptions

Read generic interfaces precisely

A template describes a family of declarations instantiated under its rules. Deduction must satisfy the declared parameter relationships; a single T for two arguments does not automatically accept every mixed-type call by guessing a preferred conversion. Explicit specialization and permitted partial specialization have different forms. A function object or lambda supplies a callable interface, while capture by value and by reference create different relationships with an enclosing object. A mutable value-capture changes the closure’s copy, not automatically the original variable.

Distinguish value categories from work

std::move is a cast enabling relevant move-aware overload resolution; it does not itself transfer resources. A later constructor or assignment determines what operation actually occurs. Moving from an object does not universally mean its value is empty or that it can be used without regard to its specified postconditions. Reference wrappers preserve a reference relationship in contexts that otherwise copy values; their lifetime still matters. Smart pointers, tuples and other utilities require their actual headers and supported language version.

Trace stream state

Formatted input and output depend on types, current flags, widths and the actual data. Some manipulators persist while others affect the next relevant insertion. State the locale and formatting assumptions when an output choice depends on them. Extraction can fail, so an input operation is not proof that a variable received a valid expected value. String position/count parameters differ from a start/end pair. Regex matching of the entire sequence differs from finding a matching subsequence; a pattern’s result does not establish a security policy by itself.

Handle failure without losing meaning

Catch a suitable exception by reference when polymorphic information should be preserved. A bare rethrow within a handler differs from throwing a copied base expression, which can slice dynamic information. Cleanup during supported stack unwinding depends on actual completed object construction and lifetime rules; not every abrupt process termination unwinds every stack. Exception guarantees describe different postconditions, including resource preservation and unchanged state where specified. These written exercises neither execute unknown code nor alter a production system, and current credential administration remains separate from their language examples.