std:: binary_negate
|
헤더 파일에 정의됨
<functional>
|
||
|
template
<
class
Predicate
>
struct
binary_negate
|
(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
explicit
binary_negate
(
Predicate
const
&
pred
)
;
|
(C++14 이후) | |
저장된 predicate 함수 객체
pred
를 가진
std::binary_negate
함수 객체를 생성합니다.
매개변수
| pred | - | predicate 함수 객체 |
std::binary_negate:: operator()
|
bool
operator
(
)
(
first_argument_type
const
&
x,
second_argument_type const & y ) const ; |
(C++14 이전) | |
|
constexpr
bool
operator
(
)
(
first_argument_type
const
&
x,
second_argument_type const & y ) const ; |
(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)
|
보유한 단항 조건자의 보수를 반환하는 래퍼 함수 객체
(클래스 템플릿) |