Namespaces
Variants

std:: unary_negate

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
unary_negate
( until C++20* )
( until C++20* )
헤더 파일에 정의됨 <functional>
template < class Predicate >
struct unary_negate : public std:: unary_function < Predicate :: argument_type , bool > ;
(C++11까지)
template < class Predicate >
struct unary_negate ;
(C++11부터)
(C++17부터 사용 중단됨)
(C++20에서 제거됨)

std::unary_negate 는 보유한 단항 술어의 보수를 반환하는 래퍼 함수 객체입니다.

단항 술어 타입은 술어의 매개변수 타입으로 변환 가능한 멤버 타입 argument_type 을 정의해야 합니다. std::ref , std::cref , std::negate , std::logical_not , std::mem_fn , std::function , std::hash 로부터 얻은 단항 함수 객체들, 또는 std::not1 에 대한 다른 호출로부터 얻은 함수 객체들은 이 타입이 정의되어 있으며, 사용 중단된 std::unary_function 에서 파생된 함수 객체들도 마찬가지입니다.

std::unary_negate 객체는 헬퍼 함수 std::not1 을 사용하여 쉽게 생성할 수 있습니다.

목차

멤버 타입

유형 정의
argument_type Predicate :: argument_type
result_type bool

멤버 함수

(constructor)
제공된 predicate를 사용하여 새로운 unary_negate 객체를 생성합니다
(public member function)
operator()
저장된 predicate 호출 결과의 논리적 보수를 반환합니다
(public member function)

std::unary_negate:: unary_negate

explicit unary_negate ( Predicate const & pred ) ;
(C++14 이전)
constexpr explicit unary_negate ( Predicate const & pred ) ;
(C++14 이후)

저장된 predicate pred 를 갖는 std::unary_negate 함수 객체를 생성합니다.

매개변수

pred - predicate 함수 객체

std::unary_negate:: operator()

bool operator ( ) ( argument_type const & x ) const ;
(C++14 이전)
constexpr bool operator ( ) ( argument_type const & x ) const ;
(C++14 이후)

pred ( x ) 호출 결과의 논리적 부정을 반환합니다.

매개변수

x - predicate에 전달할 인자

반환 값

pred ( x ) 호출 결과의 논리적 부정입니다.

예제

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
struct less_than_7 : std::unary_function<int, bool>
{
    bool operator()(int i) const { return i < 7; }
};
int main()
{
    std::vector<int> v(7, 7);
    v[0] = v[1] = v[2] = 6;
    std::unary_negate<less_than_7> not_less_than_7((less_than_7()));
    // C++11 솔루션:
    // std::function<bool (int)> 사용
    // std::function<bool (int)> not_less_than_7 =
    //     [](int x)->bool { return !less_than_7()(x); };
    std::cout << std::count_if(v.begin(), v.end(), not_less_than_7);
}

출력:

4

참고 항목

(C++17에서 사용 중단됨) (C++20에서 제거됨)
보유한 이항 조건자의 보수를 반환하는 래퍼 함수 객체
(클래스 템플릿)
(C++11)
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼
(클래스 템플릿)
주어진 호출 시그니처에서 한정자를 지원하는 모든 호출 가능 객체의 이동 전용 래퍼
(클래스 템플릿)
(C++17에서 사용 중단됨) (C++20에서 제거됨)
사용자 정의 std::unary_negate 객체를 생성함
(함수 템플릿)
(C++11에서 사용 중단됨) (C++17에서 제거됨)
함수 포인터로부터 어댑터 호환 함수 객체 래퍼를 생성함
(함수 템플릿)
(C++11에서 사용 중단됨) (C++17에서 제거됨)
어댑터 호환 단항 함수 베이스 클래스
(클래스 템플릿)