Namespaces
Variants

std::experimental:: not_fn

From cppreference.net
헤더 파일에 정의됨 <experimental/functional>
template < class F >
/*unspecified*/ not_fn ( F && f ) ;
(library fundamentals TS v2)

보유한 호출 가능 객체의 보수를 반환하는 전달 호출 래퍼를 생성합니다.

목차

매개변수

f - 래퍼가 보유한 Callable 객체가 생성되는 대상 객체

반환값

FD std:: decay_t < F > 라 하고, fd std:: forward < F > ( f ) 로부터 생성된 FD 타입의 lvalue라 하자.

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 오버로드
        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)
보유한 함수 객체의 결과의 보수를 반환하는 함수 객체를 생성합니다
(함수 템플릿)