Namespaces
Variants

std:: not2

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* )
not2
( 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:: binary_negate < Predicate > not2 ( const Predicate & pred ) ;
(C++14까지)
template < class Predicate >
constexpr std:: binary_negate < Predicate > not2 ( const Predicate & pred ) ;
(C++14부터)
(C++17부터 사용 중단)
(C++20에서 제거됨)

std::not2 는 전달된 이항 조건자 함수의 보수를 반환하는 함수 객체를 생성하기 위한 헬퍼 함수입니다. 생성된 함수 객체는 std:: binary_negate < Predicate > 타입입니다.

이진 술어 타입은 술어의 매개변수 타입으로 변환 가능한 first_argument_type second_argument_type 이라는 두 멤버 타입을 정의해야 합니다. std::owner_less , std::ref , std::cref , std::plus , std::minus , std::multiplies , std::divides , std::modulus , std::equal_to , std::not_equal_to , std::greater , std::less , std::greater_equal , std::less_equal , std::logical_not , std::logical_or , std::bit_and , std::bit_or , std::bit_xor , std::mem_fn , std::map::value_comp , std::multimap::value_comp , std::function 에서 얻은 함수 객체들, 또는 std::not2 의 다른 호출에서 얻은 함수 객체들은 이러한 타입들이 정의되어 있으며, 더 이상 사용되지 않는 std::binary_function 에서 파생된 함수 객체들도 마찬가지입니다.

목차

매개변수

pred - 이진 조건자

반환값

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

예외

(없음)

예제

#include <algorithm>
#include <cstddef>
#include <functional>
#include <iostream>
#include <vector>
struct old_same : std::binary_function<int, int, bool>
{
    bool operator()(int a, int b) const { return a == b; }
};
struct new_same
{
    bool operator()(int a, int b) const { return a == b; }
};
bool same_fn(int a, int b)
{
    return a == b;
}
int main()
{
    std::vector<int> v1{0, 1, 2};
    std::vector<int> v2{2, 1, 0};
    std::vector<bool> v3(v1.size());
    std::cout << "이항 함수 부정하기:\n";
    std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
                   std::not2(old_same()));
    std::cout << std::boolalpha;
    for (std::size_t i = 0; i < v1.size(); ++i)
        std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
    std::cout << "표준 함수 객체 부정하기:\n";
    std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
                   std::not2(std::equal_to<int>()));
    for (std::size_t i = 0; i < v1.size(); ++i)
        std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
    std::cout << "std::function 부정하기:\n";
    std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
                   std::not2(std::function<bool(int, int)>(new_same())));
    for (std::size_t i = 0; i < v1.size(); ++i)
        std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
    std::cout << "std::reference_wrapper 부정하기:\n";
    std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
                   std::not2(std::ref(same_fn)));
    for (std::size_t i = 0; i < v1.size(); ++i)
        std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
}

출력:

binary_function 부정:
0 2 true
1 1 false
2 0 true
표준 functor 부정:
0 2 true
1 1 false
2 0 true
std::function 부정:
0 2 true
1 1 false
2 0 true
std::reference_wrapper 부정:
0 2 true
1 1 false
2 0 true

참고 항목

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