Namespaces
Variants

std:: not1

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* )
not1
( 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* )
( until C++20* )
( until C++20* )
헤더 파일에 정의됨 <functional>
template < class Predicate >
std:: unary_negate < Predicate > not1 ( const Predicate & pred ) ;
(C++14까지)
template < class Predicate >
constexpr std:: unary_negate < Predicate > not1 ( const Predicate & pred ) ;
(C++14부터)
(C++17에서 사용 중단됨)
(C++20에서 제거됨)

std::not1 는 전달된 단항 술어 함수의 보수를 반환하는 함수 객체를 생성하기 위한 헬퍼 함수입니다. 생성된 함수 객체는 std:: unary_negate < Predicate > 타입입니다.

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

목차

매개변수

pred - 단항 술어

반환값

std::not1 std:: unary_negate < Predicate > 타입의 객체를 반환하며, 이는 pred 로 구성됩니다.

예외

(없음)

예제

#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
struct LessThan7 : std::unary_function<int, bool>
{
    bool operator()(int i) const { return i < 7; }
};
int main()
{
    std::vector<int> v(10);
    std::iota(std::begin(v), std::end(v), 0);
    std::cout << std::count_if(begin(v), end(v), std::not1(LessThan7())) << '\n';
    // 위와 동일한 로직을 std::function을 사용하여 구현
    std::function<bool(int)> less_than_9 = [](int x) { return x < 9; };
    std::cout << std::count_if(begin(v), end(v), std::not1(less_than_9)) << '\n';
}

출력:

3
1

참고 항목

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