Namespaces
Variants

std::experimental:: not_fn

From cppreference.net
ヘッダーで定義 <experimental/functional>
template < class F >
/*unspecified*/ not_fn ( F && f ) ;
(ライブラリ基盤 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)...);
        }
        // QoIのためのcv修飾オーバーロード
        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)
保持している関数オブジェクトの結果の補数を返す関数オブジェクトを作成する
(関数テンプレート)