[ Web Proxy ]
URL:
Viewing: https://en.cppreference.com/cpp/types/is_applicable [Back]  [Original]

std::is_applicable, std::is_nothrow_applicable - cppreference.com
cppreference.com
Namespaces
Variants

std::is_applicable, std::is_nothrow_applicable

From cppreference.com
 
 
 
Type traits
Type traits (since C++11)
Type categories
Type properties
(C++14)
(deprecated in C++26)
(until C++20*)
(deprecated in C++20)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(deprecated in C++23)
(deprecated in C++23)
(until C++20*)(C++17)
 
Defined in header <type_traits>
template< class Fn, class Tuple >
struct is_applicable;
(1) (since C++26)
template< class Fn, class Tuple >
struct is_nothrow_applicable;
(2) (since C++26)

Checks if the type Fn can be invoked (as if by std::invoke) with the given tuple Tuple of arguments.

Let /*ELEMS-OF*/(T) be the parameter pack std::get<N>(std::declval<T>()), where N is the pack of std::size_t template arguments of the specialization of std::index_sequence denoted by std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<T>>>.

1) Checks if tuple-like<Tuple> is true and INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) is well-formed when treated as an unevaluated operand.
2) Checks if std::is_applicable_v<Fn, Tuple> is true and INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) is known not to throw any exceptions.

If Fn or Tuple 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.

Helper variable templates

Defined in header <type_traits>
template< class Fn, class Tuple >
constexpr bool is_applicable_v = is_applicable<Fn, Tuple>::value;
(1) (since C++26)
template< class Fn, class Tuple >
constexpr bool is_nothrow_applicable_v = is_nothrow_applicable<Fn, Tuple>::value;
(2) (since C++26)

Inherited from std::integral_constant

Member constants

value
[static]
true if (for overload (1)) INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) 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

Feature-test macro Value Std Feature
__cpp_lib_reflection 202506L (C++26) <meta>: Reflection library support.

Examples

#include <tuple>
#include <type_traits>
#include <utility>

void func(char) noexcept;

static_assert(
    std::is_applicable_v<int(), std::tuple<>> and
    not std::is_applicable_v<int(), std::tuple<int>> and
    std::is_applicable_v<std::declval(func), std::tuple<char>> and
    not std::is_applicable_v<std::declval(func), std::tuple<char, int>> and
    std::is_nothrow_applicable_v<std::declval(func), std::tuple<char>>
);

int main() {}

See also

(C++17)
calls a function with a tuple of arguments
(function template) [edit]
(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]
specifies that a callable type can be invoked with a given set of argument types
(concept) [edit]
checks if a type can be invoked (as if by std::invoke) with the given argument types
(class template) [edit]
checks if the reflected type can be invoked (as if by std::invoke) with the given argument types
(function template) [edit]
checks if a reflected type can be invoked (as if by std::invoke) with the given reflected tuple of arguments
(function) [edit]

Web Proxy Viewer  |  New URL  |  Original Page