Namespaces
Variants

std:: not_equal_to

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* )
( 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 T >
struct not_equal_to ;
(C++14 前)
template < class T = void >
struct not_equal_to ;
(C++14 起)

用于执行比较的函数对象。除非特化,否则调用类型 T 上的 operator ! =

目录

特化

当未指定 T 时,标准库提供了 std::not_equal_to 的特化版本,该版本会推导参数类型和返回类型。

实现 x ! = y 并推导参数和返回类型的函数对象
(类模板特化)
(C++14 起)

成员类型

类型 定义
result_type (C++17 中弃用) (C++20 中移除) bool
first_argument_type (C++17 中弃用) (C++20 中移除) T
second_argument_type (C++17 中弃用) (C++20 中移除) T

这些成员类型通过公开继承 std:: binary_function < T, T, bool > 获得。

(C++11 前)

成员函数

operator()
检查参数是否 不相等
(公开成员函数)

std::not_equal_to:: operator()

bool operator ( ) ( const T & lhs, const T & rhs ) const ;
(constexpr since C++14)

检查 lhs 是否 不等于 rhs

参数

lhs, rhs - 要比较的值

返回值

lhs ! = rhs 则为 true ,否则为 false

异常

可能抛出由实现定义的异常。

可能的实现

constexpr bool operator()(const T& lhs, const T& rhs) const 
{
    return lhs != rhs;
}

参见

判断两组元素是否相同
(函数模板)
实现 x < y 运算的函数对象
(类模板)
实现 x ! = y 运算的约束函数对象
(类)