命名空间
变体
操作

std::invocable, std::regular_invocable

来自 cppreference.cn
< cpp‎ | 概念
定义于头文件 <concepts>
template< class F, class... Args >

concept invocable =
    requires(F&& f, Args&&... args) {
        std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
            /* 不要求是等式保持的 */

    };
(since C++20)
template< class F, class... Args >
concept regular_invocable = std::invocable<F, Args...>;
(since C++20)

invocable 概念指定可调用类型 F 可以使用函数模板 std::invoke 和一组参数 Args... 一起调用。

regular_invocable 概念在 invocable 概念的基础上增加了要求,即 invoke 表达式必须是等式保持的,并且不修改函数对象或参数。

目录

[编辑] 等式保持

标准库概念的 requires 表达式 中声明的表达式需要是等式保持的(除非另有说明)。

[编辑] 注释

invocableregular_invocable 之间的区别纯粹是语义上的。

随机数生成器可能满足 invocable,但不能满足 regular_invocable (排除滑稽的例子)。

[编辑] 参考

  • C++23 标准 (ISO/IEC 14882:2024)
  • 18.7.2 概念 invocable [concept.invocable]
  • 18.7.3 概念 regular_invocable [concept.regularinvocable]
  • C++20 标准 (ISO/IEC 14882:2020)
  • 18.7.2 概念 invocable [concept.invocable]
  • 18.7.3 概念 regular_invocable [concept.regularinvocable]

[编辑] 参见

检查一个类型是否可以使用给定的参数类型调用(如同通过 std::invoke 调用一样)
(类模板) [编辑]

[编辑] 外部链接

一个笑话例子,展示了一个同时满足 invocableregular_invocable 的随机数生成器。