Namespaces
Variants

std::unary_negate

cppreference.net에서
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교체 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
함수 객체
함수 호출
(C++17)(C++23)
항등 함수 객체
(C++20)
투명 연산자 래퍼
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

이전 바인더 및 어댑터
(C++17까지*)
(C++17까지*)
(C++17까지*)
(C++17까지*)  
(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
(C++17까지*)(C++17까지*)
(C++17까지*)(C++17까지*)

(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(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 );
(constexpr since C++14)

저장된 조건자 std::unary_negate를 사용하여 pred 함수 객체를 생성합니다.

매개변수

pred - predicate 함수 객체

std::unary_negate::operator()

bool operator()( argument_type const& x ) const;
(constexpr since 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에서 제거됨)
어댑터 호환 단항 함수 베이스 클래스
(클래스 템플릿)