Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 以下小于(<;)运算符适用于哪些类型的T?_C++_C++11_Operator Overloading_C++ Concepts - Fatal编程技术网

C++ 以下小于(<;)运算符适用于哪些类型的T?

C++ 以下小于(<;)运算符适用于哪些类型的T?,c++,c++11,operator-overloading,c++-concepts,C++,C++11,Operator Overloading,C++ Concepts,当我读到的书“”时,我遇到了他提到的以下问题(第07页)。大约是小于( 解释使该定义合法的对T的要求是什么 模板 bool运算符可供解释。如果您能为这种类型提供“实例均被视为“相等”的任何类型”的示例,那就太好了。@MantoshKumarstruct AllTheSame{};。关键是“始终为false”operator@MantoshKumar一个真实的例子:如果一个库容器分配的内存可以被另一个容器释放,那么标准库容器的分配器必须比较相等。默认分配器就是这种情况,因此所有实例(例如,std:

当我读到的书“”时,我遇到了他提到的以下问题(第07页)。大约是小于( 解释使该定义合法的对T的要求是什么

模板

bool运算符可供解释。如果您能为这种类型提供“实例均被视为“相等”的任何类型”的示例,那就太好了。@MantoshKumar
struct AllTheSame{};
。关键是“始终为false”
operator@MantoshKumar一个真实的例子:如果一个库容器分配的内存可以被另一个容器释放,那么标准库容器的分配器必须比较相等。默认分配器就是这种情况,因此所有实例(例如,
std::allocator
比较相等。(同样,不需要对分配器进行总计排序-它们通常定义
运算符==
运算符!=
,但不定义
运算符。)
template<typename T>
bool operator<(const T& x, const T& y) {
  return true;
}
template<typename T>
bool operator<(const T& x, const T& y) {
  return false;
}
class test { };
test x;
test y;
// &x = 0x7fffffffe0bd, &y = 0x7fffffffe0be
bool out = &y < &x;
//out = 0;
template<typename T>
bool operator<(const T& x, const T& y) {
  return false;
}
a < b; // false
b < a; // false