std::experimental::not_fn
From cppreference.com
< cpp | experimental
| ヘッダ <experimental/functional> で定義 |
||
| template< class F> /*未指定*/ not_fn( F&& f ); |
(Library Fundamentals TS v2) | |
保持している呼び出し可能オブジェクトの補数を返す、フォワーディング呼び出しラッパーを作成します。
目次 |
[編集] パラメータ
| f | - | ラッパーが保持する Callable オブジェクトが構築される元のオブジェクト |
[編集] 戻り値
FD を std::decay_t<F> とし、fd を std::forward<F>(f) から構築された型 FD の左辺値とします。
not_fn は、未指定の型のフォワーディング呼び出しラッパー fn を返します。このラッパーにおいて fn(a1, a2, ..., aN) は !INVOKE(fd, a1, ..., aN) と同等です。ここで INVOKE は Callable で説明されている操作です。
返される呼び出しラッパーは常に MoveConstructible であり、FD が CopyConstructible の場合は CopyConstructible になります。
[編集] 備考
fd が Callable でない場合、または std::is_constructible<FD, F>::value が true でない場合、動作は未定義です。
[編集] 例外
fd の構築が例外をスローしない限り、例外はスローされません。
[編集] 実装例
namespace detail { template<class F> struct not_fn_t { F f; template<class... Args> auto operator()(Args&&... args) noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } // cv-qualified overload for QoI template<class... Args> auto operator()(Args&&... args) const noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } template<class... Args> auto operator()(Args&&... args) volatile noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } template<class... Args> auto operator()(Args&&... args) const volatile noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } }; } template<class F> detail::not_fn_t<std::decay_t<F>> not_fn(F&& f) { return { std::forward<F>(f) }; } |
[編集] 注
not_fn は、C++03 時代のネゲータである std::not1 および std::not2 を置き換えることを目的としています。
[編集] 関連項目
| (C++17) |
保持する関数オブジェクトの結果の補数を返す関数オブジェクトを作成する (関数テンプレート) |