liveBook · Manning

Operator""h

As explained in Learn C++ by Example

operator""h is the C++ chrono user-defined literal operator that converts a numeric literal with the h suffix to an hours duration.

operator""h is the chrono user-defined literal that turns a numeric h-suffixed literal into an hours duration. Thus, 23h provides a readable alternative to hours{23}. section 4.2.3

Readable duration syntax

When 23h is encountered, operator""h is called with the numeric value and returns hours(23). Make chrono literals visible through std::chrono, std::literals, or std::chrono_literals. section 4.2.3

hours operator""h(long long _Val) {
   return hours(_Val);
}

A simplified implementation shows the literal operator accepting a long long value and returning the stronger hours type. section 4.2.3

How Learn C++ by Example covers it

How deep it goes
Explains the call and simplified implementation, while deferring specification-level operator details.
Examples
Uses 23h beside hours{23} and sketches an operator returning hours(_Val).
What it assumes
Assumes basic C++ literals and namespaces while introducing user-defined literals through chrono duration syntax.
What you can do after
Apply it via chrono namespace access to write hour durations as readable numeric literals.
How it connects
Connects user-defined literals with chrono durations, namespace directives, and related minute, second, and subsecond literals.

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.