Namespaces
Variants
Views
Actions

std::is_callable, std::is_nothrow_callable

From cppreference.com
< cpp‎ | types
Revision as of 16:48, 13 March 2017 by T. Canens (Talk | contribs)

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
 
Defined in header <type_traits>
template <class, class R = void> struct is_callable; // not defined


template <class Fn, class... ArgTypes, class R>

struct is_callable<Fn(ArgTypes...), R>;
(1) (since C++17)
template <class, class R = void> struct is_nothrow_callable; // not defined


template <class Fn, class... ArgTypes, class R>

struct is_nothrow_callable<Fn(ArgTypes...), R>;
(2) (since C++17)
1) Determines whether Fn is callable with the arguments ArgTypes... and the result would be convertible to R. Formally, determines whether INVOKE(declval<Fn>(), declval<ArgTypes>()..., R) is well formed when treated as an unevaluated operand, where INVOKE is the operation defined in Template:concept.
2) Determines whether Fn is callable with the arguments ArgTypes... and the result would be convertible to R (same as (1)), and that such call is known not to throw any exceptions.

If Fn, R or any type in the parameter pack Args 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.

Contents

Helper variable templates

Defined in header <type_traits>
template <class T, class R = void>
constexpr bool is_callable_v  = std::is_callable<T, R>::value;
(1) (since C++17)
template <class T, class R = void>
constexpr bool is_nothrow_callable_v = std::is_nothrow_callable<T, R>::value;
(2) (since C++17)

Inherited from std::integral_constant

Member constants

value
[static]
true if INVOKE(declval<Fn>(), declval<ArgTypes>()..., R) is well formed when treated as an unevaluated operand , false otherwise
(public static member constant)

Member functions

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

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

Notes

Version (1) of this trait may be implemented in terms of std::is_convertible and std::result_of.

Examples

See also

(C++17)(C++23)
invokes any Callable object with given arguments and 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]