liveBook · Manning

Using keyword

As explained in Learn C++ by Example

A using statement is C++ syntax that introduces a name or defines an alias for a type or declaration.

The using keyword creates an alias for an existing type or declaration. It offers a clearer alternative to typedef and can describe families of templates. section 8.2 section 8.4

Naming tuple and pair types

A lookup table can use short aliases instead of repeating long compound types: state_t names a tuple containing two outcomes and a choice, while last_choices_t names a pair of choices. The aliases make the state representation easier to read. section 8.2

Defining a custom duration

A type alias can give a meaningful name to a complex chrono duration. The centuries alias combines a long-long representation with a period calculated from years and hecto, then behaves like other duration types. section 4.2.2

How Learn C++ by Example covers it

How deep it goes
Defines aliases through practical examples and notes template-family support, but stops short of a full syntax catalogue.
Examples
Uses matching-pennies state aliases and a centuries duration to demonstrate readable names for compound types.
What it assumes
Assumes familiarity with typedef, tuples, pairs, templates, and chrono duration types.
What you can do after
Apply using to replace typedef and name compound or parameterized types in practical C++ code.
How it connects
Connects type aliases with typedef, templates, tuples, pairs, and chrono durations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.