liveBook · Manning

Invocable

As explained in Learn C++ by Example

invocable is a C++ standard concept requiring that a callable object can be invoked with a specified set of arguments.

invocable is a C++ standard concept that constrains a callable object to accept a specified set of arguments. Applying it to a parameter makes the required call shape explicit and moves unsuitable arguments toward clearer constraint diagnostics. section 4.2.4

Constraining a message callback

A number-guessing function can require a message callable with two integers: `void guess_number_with_clues(int number, std::invocable<int, int> auto message)`. Passing a string literal instead produces an associated-constraints diagnostic at the function boundary rather than an error inside the attempted call. section 4.2.4

The constraint also supports generic designs and testing. A random blob can require a generator invocable with no arguments, while a deterministic lambda returning zero can replace randomness in a test. section 6.2.1

Injecting a shuffle operation

A reel-building function can constrain its shuffle parameter with `std::invocable<std::vector<Reel>::iterator, std::vector<Reel>::iterator>`. Production code supplies a lambda that calls `std::shuffle`; a no-op lambda enables a constexpr check. section 9.2.1

How Learn C++ by Example covers it

How deep it goes
Explains callable constraints, diagnostics, and substitutions through examples, but stops short of the complete concepts system.
Examples
Uses a guessing-game message callback, a random blob generator, and a slot-machine reel shuffler with deterministic test replacements.
What it assumes
Assumes templates and callable objects while building from parameter constraints toward practical lambda-based callbacks and test doubles.
What you can do after
Apply it via the C++ concepts library to constrain callable parameters and obtain more targeted compile-time diagnostics.
How it connects
Connects concepts with templates, lambda expressions, generic programming, random number generation, testing, and constexpr functions.

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.