名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | types
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
(C++11)
(C++11)
is_invocableis_invocable_ris_nothrow_invocableis_nothrow_invocable_r
(C++17)(C++17)(C++17)(C++17)
型変更
型変換
(C++11)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
ヘッダ <type_traits> で定義
template<class Fn, class... ArgTypes>
struct is_invocable;
(1) (C++17以上)
template<class R, class Fn, class... ArgTypes>
struct is_invocable_r;
(2) (C++17以上)
template<class Fn, class... ArgTypes>
struct is_nothrow_invocable;
(3) (C++17以上)
template<class R, class Fn, class... ArgTypes>
struct is_nothrow_invocable_r;
(4) (C++17以上)
1)Fn が引数 ArgTypes... で呼び出すことができるかどうか調べます。 形式的には、未評価の被演算子として扱われたときに INVOKE(declval<Fn>(), declval<ArgTypes>()...) が well-formed であるかどうかを調べます。 ただし INVOKECallable で定義されている操作です。
2)FnR に変換可能な結果を生成するために引数 ArgTypes... で呼び出すことができるかどうか調べます。 形式的には、未評価の被演算子として扱われたときに INVOKE<R>(declval<Fn>(), declval<ArgTypes>()...) が well-formed であるかどうかを調べます。 ただし INVOKECallable で定義されている操作です。
3)Fn が引数 ArgTypes... で呼び出すことができるかどうか ((1) と同じ)、そしてそのような呼び出しがいかなる例外も投げないと判っているかどうか調べます。
4)FnR に変換可能な結果を生成するために引数 ArgTypes... で呼び出すことができるかどうか ((2) と同じ)、そしてそのような呼び出し (変換を含む) がいかなる例外も投げないと判っているかどうか調べます。

Fn, R およびパラメータパック ArgTypes 内のすべての型 はいずれも完全型 (またはその cv 修飾された型)、 void、またはサイズの未知な配列でなければなりません。 そうでなければ、動作は未定義です。

上記のテンプレートの実体化が直接または間接的に不完全型に依存しており、もしその型が仮に完全型であったならばその実体化が異なる結果を産むであろう場合は、動作は未定義です。

目次

[編集] ヘルパー変数テンプレート

ヘッダ <type_traits> で定義
template<class Fn, class... ArgTypes>
inlineconstexprbool is_invocable_v = std::is_invocable<Fn, ArgTypes...>::value;
(1) (C++17以上)
template<class R, class Fn, class... ArgTypes>
inlineconstexprbool is_invocable_r_v = std::is_invocable_r<R, Fn, ArgTypes...>::value;
(2) (C++17以上)
template<class Fn, class... ArgTypes>
inlineconstexprbool is_nothrow_invocable_v = std::is_nothrow_invocable<Fn, ArgTypes...>::value;
(3) (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) (C++17以上)

std::integral_constant から継承

メンバ定数

value
[静的]
未評価の被演算子として扱われたときに INVOKE<R>(declval<Fn>(), declval<ArgTypes>()...) が well-defined ならば true、そうでなければ false
(パブリック静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換します。 value を返します
(パブリックメンバ関数)
operator()
(C++14)
value を返します
(パブリックメンバ関数)

メンバ型

定義
value_typebool
typestd::integral_constant<bool, value>

[編集]

#include <type_traits>   auto func2(char)->int(*)(){return nullptr;}   int main(){ static_assert( std::is_invocable<int()>::value); static_assert( std::is_invocable_r<int, int()>::value); static_assert( std::is_invocable_r<void, void(int), int>::value); static_assert( std::is_invocable_r<int(*)(), decltype(func2), char>::value);}


[編集]関連項目

(C++17)
任意の Callable なオブジェクトを指定された引数で呼びます
(関数テンプレート)[edit]
(C++11)(C++20で削除)(C++17)
指定された引数のセットを渡して callable なオブジェクトを呼んだときの結果の型を推定します
(クラステンプレート)[edit]
(C++11)
未評価文脈で使用するための引数への参照を取得します
(関数テンプレート)[edit]
close