std::is_inv..._invocable,(3)

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

🌸 NAME 🌸

Okay so bestie 🫢 we're looking at std::is_inv..._invocable,(3) from the C++ Standard Libary manual β€” and yes, "Libary" is literally how the header spells it, we don't fix, we appreciate πŸ’…. The NAME line is:

std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable, - std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable,

Also, std::is_nothrow_invocable_r shows up in the synopsis below, so keep your eyes peeled πŸ‘€. Every crumb stays.


✨ Synopsis ✨

Defined in header <type_traits>.

template< class Fn, class... ArgTypes >          (1) (since C++17)
struct is_invocable;
template< class R, class Fn, class... ArgTypes > (2) (since C++17)
struct is_invocable_r;
template< class Fn, class... ArgTypes >          (3) (since C++17)
struct is_nothrow_invocable;
template< class R, class Fn, class... ArgTypes > (4) (since C++17)
struct is_nothrow_invocable_r;

The four overloads are giving very specific vibe checks:

  1. Determines whether INVOKE(std::declval<Fn>(), std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand.
  2. Determines whether INVOKE<R>(std::declval<Fn>(), std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand.
  3. Determines whether INVOKE(std::declval<Fn>(), std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, and is known not to throw any exceptions.
  4. Determines whether INVOKE<R>(std::declval<Fn>(), std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, and is known not to throw any exceptions.
🚨 Behavior is undefined if Fn, R, or any type in the parameter pack ArgTypes is not a complete type, is (possibly cv-qualified) void, or is an array of unknown bound.
🚨 If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the behavior is undefined.
🚨 If the program adds specializations for any of the templates described on this page, the behavior is undefined.

πŸŽ€ Member constants πŸŽ€

  • value [static] β€” true if (for overload (1)) INVOKE(std::declval<Fn>(), std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, false otherwise. This is a public static member constant.

πŸ’… Member functions πŸ’…

  • operator bool β€” converts the object to bool, returns value (public member function)
  • operator() β€” returns value (C++14) (public member function)

πŸ¦‹ Member types πŸ¦‹

  • value_type β€” bool
  • type β€” std::integral_constant<bool, value>

🌈 Notes 🌈

Feature-test macro tea:

  • Macro: __cpp_lib_is_invocable
  • Value: 201703L
  • Std: (C++17)
  • Feature: std::is_invocable, std::invoke_result

πŸ”₯ Examples πŸ”₯

// Run this code

#include <type_traits>

auto func2(char) -> int (*)()
{
    return nullptr;
}

int main()
{
    static_assert(std::is_invocable_v<int()>);
    static_assert(not std::is_invocable_v<int(), int>);
    static_assert(std::is_invocable_r_v<int, int()>);
    static_assert(not std::is_invocable_r_v<int*, int()>);
    static_assert(std::is_invocable_r_v<void, void(int), int>);
    static_assert(not std::is_invocable_r_v<void, void(int), void>);
    static_assert(std::is_invocable_r_v<int(*)(), decltype(func2), char>);
    static_assert(not std::is_invocable_r_v<int(*)(), decltype(func2), void>);
}

🌟 See also 🌟

  • invoke β€” invokes any Callable object with given arguments
  • invoke_r β€” and possibility to specify return type; tags from this cluster: (C++17) (since C++23) (C++23) (function template)
  • result_of β€” deduces the result type of invoking a callable object with
  • invoke_result β€” a set of arguments; the original page's tags for this cluster are (C++11)(removed in C++20) (class template) (C++17) β€” yes, the line-wrapping is chaotic 😭
  • declval β€” obtains a reference to its argument for use in unevaluated (C++11) context (function template)
  • invocable β€” specifies that a callable type can be invoked with a given
  • regular_invocable β€” set of argument types; (C++20) (concept)

Bye bestie πŸ’– this iconic page came from http://cppreference.com, dated 2024.06.10 β€” slay.

πŸ“¦ where this page comes from