std::invoca...ar_invocable(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

std::invocable,std::regular_invocable β€” and then, because why not, it says std::invocable,std::regular_invocable again. This is the page for std::invoca...ar_invocable(3), from the C++ Standard Libary manual (their spelling, not mine πŸ’€).


✨ Synopsis ✨

Okay so it’s defined in the header <concepts>, bestie. The synopsis is giving template-concept realness:

template< class F, class... Args >
concept invocable =
    requires(F&& f, Args&&... args) {
        std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
            /* not required to be equality-preserving */
    };

template< class F, class... Args >
concept regular_invocable = std::invocable<F, Args...>;

Both of these are since C++20 ✨

The invocable concept specifies that a callable type F can be called with a set of arguments Args... using the function template std::invoke. Slay.

The regular_invocable concept adds to the invocable concept by requiring the invoke expression to be equality-preserving and not modify either the function object or the arguments. Periodt.


πŸ¦‹ Notes πŸ¦‹

The distinction between invocable and regular_invocable is purely semantic.

A random number generator may satisfy invocable but cannot satisfy regular_invocable (comical ones excluded). Not me side-eyeing the random number generators πŸ’…


πŸ’œ See also πŸ’œ

  • is_invocable
  • is_invocable_r
  • is_nothrow_invocable
  • is_nothrow_invocable_r

The whole little squad checks if a type can be invoked (as if by std::invoke) with the given argument types. They’re a class template, and they’re C++17 πŸ‘‘


  1. A joke example of a random number generator that satisfies both invocable and regular_invocable.

mwah πŸ’‹ β€” source/version: http://cppreference.com; date: 2024.06.10; page: std::invoca...ar_invocable(3). That’s the footer, bestie, not me ignoring it 🫢

πŸ“¦ where this page comes from