Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::is_invocable,std::is_invocable_r,std::is_nothrow_invocable,std::is_nothrow_invocable_r

      From cppreference.com
      <cpp‎ |types
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      Type properties
      (C++11)
      (C++11)
      (C++14)
      (C++11)(deprecated in C++26)
      (C++11)(until C++20*)
      (C++11)(deprecated in C++20)
      (C++11)
      Type trait constants
      Metafunctions
      (C++17)
      Supported operations
      Relationships and property queries
      (C++11)
      (C++11)
      (C++11)
      is_invocableis_invocable_ris_nothrow_invocableis_nothrow_invocable_r
      (C++17)(C++17)(C++17)(C++17)
      Type modifications
      Type transformations
      (C++11)(deprecated in C++23)
      (C++11)(deprecated in C++23)
      (C++11)
      (C++11)(until C++20*)(C++17)

      Compile-time rational arithmetic
      Compile-time integer sequences
       
      Defined in header<type_traits>
      template<class Fn,class...ArgTypes>
      struct is_invocable;
      (1)(since C++17)
      template<class R,class Fn,class...ArgTypes>
      struct is_invocable_r;
      (2)(since C++17)
      template<class Fn,class...ArgTypes>
      struct is_nothrow_invocable;
      (3)(since C++17)
      template<class R,class Fn,class...ArgTypes>
      struct is_nothrow_invocable_r;
      (4)(since C++17)
      1) Determines whetherINVOKE(std::declval<Fn>(),std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand.
      2) Determines whetherINVOKE<R>(std::declval<Fn>(),std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand.
      3) Determines whetherINVOKE(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 whetherINVOKE<R>(std::declval<Fn>(),std::declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, and is known not to throw any exceptions.

      IfFn, R or any type in the parameter packArgTypes is not a complete type, (possibly cv-qualified)void, or an array of unknown bound, the behavior is undefined.

      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.

      Contents

      [edit]Helper variable templates

      Defined in header<type_traits>
      template<class Fn,class...ArgTypes>

      inlineconstexprbool is_invocable_v=

          std::is_invocable<Fn, ArgTypes...>::value;
      (1)(since C++17)
      template<class R,class Fn,class...ArgTypes>

      inlineconstexprbool is_invocable_r_v=

          std::is_invocable_r<R, Fn, ArgTypes...>::value;
      (2)(since C++17)
      template<class Fn,class...ArgTypes>

      inlineconstexprbool is_nothrow_invocable_v=

          std::is_nothrow_invocable<Fn, ArgTypes...>::value;
      (3)(since C++17)
      template<class R,class Fn,class...ArgTypes>

      inlineconstexprbool is_nothrow_invocable_r_v=

          std::is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
      (4)(since C++17)
      [edit]

      Inherited fromstd::integral_constant

      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
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_is_invocable201703L(C++17)std::is_invocable,std::invoke_result

      [edit]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>);}

      [edit]See also

      (C++17)(C++23)
      invokes anyCallable object with given argumentsand possibility to specify return type(since C++23)
      (function template)[edit]
      (C++11)(removed in C++20)(C++17)
      deduces the result type of invoking a callable object with a set of arguments
      (class template)[edit]
      (C++11)
      obtains a reference to an object of the template type argument for use in an unevaluated context
      (function template)[edit]
      specifies that a callable type can be invoked with a given set of argument types
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/is_invocable&oldid=158894"

      [8]ページ先頭

      ©2009-2025 Movatter.jp