functional_unary_negate
functional_unary_negate (단항 조건자 부정 함수 객체)
std::unary_negate는 보관 중인 단항 조건자(predicate)의 부정(보완) 결과를 반환하는 래퍼 함수 객체예요. 이 타입은 C++17에서 deprecated로 지정되었고 C++20에서 제거되었어요. 헬퍼 함수 std::not1을 사용하면 std::unary_negate 객체를 쉽게 생성할 수 있어요.
출처: cppreference
본문
헤더 <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에서 deprecated) (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 호출에서 얻은 단항 함수 객체는 이 타입이 정의되어 있으며, deprecated된 std::unary_function에서 파생된 함수 객체도 마찬가지예요.
std::unary_negate 객체는 헬퍼 함수 std::not1을 사용해 쉽게 생성할 수 있어요.
멤버 타입
| 타입 | 정의 |
|---|---|
argument_type |
Predicate::argument_type |
result_type |
bool |
멤버 함수
| (생성자) | 제공된 조건자로 새 unary_negate 객체를 생성해요 (공개 멤버 함수) |
|---|---|
operator() |
저장된 조건자 호출 결과의 논리적 부정을 반환해요 (공개 멤버 함수) |
std::unary_negate::unary_negate
explicit unary_negate ( Predicate const & pred ); |
(C++14부터 constexpr) |
|---|
저장된 조건자 pred로 std::unary_negate 함수 객체를 생성해요.
매개변수
| pred | - | 조건자 함수 객체 |
std::unary_negate::operator()
bool operator ()( argument_type const & x ) const ; |
(C++14부터 constexpr) |
|---|
pred(x) 호출 결과의 논리적 부정을 반환해요.
매개변수
| x | - | 조건자에 전달할 인수 |
반환값
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 solution:
// Use 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
같이 보기
binary_negate (C++17에서 deprecated, C++20에서 제거) |
보관 중인 이항 조건자의 부정을 반환하는 래퍼 함수 객체 (클래스 템플릿) [edit] |
|---|---|
function (C++11) |
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼 (클래스 템플릿) [edit] |
move_only_function (C++23) |
주어진 호출 시그니처에서 한정사를 지원하는 모든 호출 가능 객체의 이동 전용 래퍼 (클래스 템플릿) [edit] |
not1 (C++17에서 deprecated, C++20에서 제거) |
사용자 정의 std::unary_negate 객체를 생성해요 (함수 템플릿) [edit] |
ptr_fun (C++11에서 deprecated, C++17에서 제거) |
함수 포인터로부터 어댑터 호환 함수 객체 래퍼를 생성해요 (함수 템플릿) [edit] |
unary_function (C++11에서 deprecated, C++17에서 제거) |
어댑터 호환 단항 함수 기본 클래스 (클래스 템플릿) [edit] |