std::binary_negate
| 헤더 <functional>
|
||
template< class Predicate >
struct binary_negate
: public std::binary_function<
Predicate::first_argument_type,
Predicate::second_argument_type,
bool
>;
|
에 정의됨 (C++11까지) | |
template< class Predicate >
struct binary_negate;
|
(C++11부터) (C++17에서 폐지됨) (C++20에서 제거됨) |
|
std::binary_negate는 보유한 이항 술어의 보수를 반환하는 래퍼 함수 객체입니다.
이항 술어 형식은 술어의 매개변수 형식으로 변환 가능한 두 개의 멤버 형식 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에서 파생된 함수 객체도 마찬가지입니다.
std::binary_negate객체는 도우미 함수 std::not2로 쉽게 생성됩니다.
멤버 유형
| 유형 | 정의 |
first_argument_type
|
Predicate::first_argument_type
|
second_argument_type
|
Predicate::second_argument_type
|
result_type
|
bool
|
멤버 함수
|
(constructor)
|
제공된 predicate를 사용하여 새로운 binary_negate 객체를 생성합니다
(public member function) |
|
operator()
|
저장된 predicate 호출 결과의 논리적 보수를 반환합니다
(public member function) |
std::binary_negate::binary_negate
explicit binary_negate( Predicate const& pred );
|
(C++14부터 constexpr) | |
저장된 조건자(predicate) std::binary_negate를 가진 함수 객체를 생성합니다pred.
매개변수
| pred | - | predicate 함수 객체 |
std::binary_negate::operator()
bool operator()( first_argument_type const& x,
second_argument_type const& y ) const;
|
(constexpr since C++14) | |
pred(x, y)의 호출 결과에 대한 논리적 보수를 반환합니다.
매개변수
| x | - | predicate에 전달할 첫 번째 인자 |
| y | - | predicate에 전달할 두 번째 인자 |
반환값
pred ( x, y ) 호출 결과의 논리적 보수입니다.
예제
#include <algorithm> #include <cstddef> #include <functional> #include <iostream> #include <vector> struct same : std::binary_function<int, int, bool> { bool operator()(int a, int b) const { return a == b; } }; int main() { std::vector<int> v1; for (int i = 0; i < 7; ++i) v1.push_back(i); std::vector<int> v2(v1.size()); std::reverse_copy(v1.begin(), v1.end(), v2.begin()); std::vector<bool> v3(v1.size()); std::binary_negate<same> not_same((same())); // C++11 솔루션: // std::function<bool (int, int)> not_same = // [](int x, int y) -> bool { return !same()(x, y); }; std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), not_same); std::cout.setf(std::ios_base::boolalpha); for (std::size_t i = 0; i != v1.size(); ++i) std::cout << v1[i] << " != " << v2[i] << " : " << v3[i] << '\n'; }
출력:
0 != 6 : true 1 != 5 : true 2 != 4 : true 3 != 3 : false 4 != 2 : true 5 != 1 : true 6 != 0 : true
참고 항목
|
(deprecated in C++11)
(removed in C++17)
|
어댑터 호환 이항 함수 베이스 클래스
(클래스 템플릿) |
|
(C++11)
|
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼
(클래스 템플릿) |
|
(C++23)
|
주어진 호출 시그니처에서 한정자를 지원하는 모든 호출 가능 객체의 이동 전용 래퍼
(클래스 템플릿) |
|
(deprecated in C++17)
(removed in C++20)
|
사용자 정의
std::binary_negate
객체를 생성함
(함수 템플릿) |
|
(deprecated in C++11)
(removed in C++17)
|
함수 포인터로부터 어댑터 호환 함수 객체 래퍼를 생성함
(함수 템플릿) |
|
(deprecated in C++17)
(removed in C++20)
|
보유한 단항 조건자의 보수를 반환하는 래퍼 함수 객체
(클래스 템플릿) |