operators (std::tuple)
运算符=,%21=,<,<=,>=%28std::tuple%29
Defined in header | | |
---|---|---|
template< class... TTypes, class... UTypes > bool operator==( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (1) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator==( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (1) | (since C++14) |
template< class... TTypes, class... UTypes > bool operator!=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (2) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator!=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (2) | (since C++14) |
template< class... TTypes, class... UTypes > bool operator<( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (3) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator<( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (3) | (since C++14) |
template< class... TTypes, class... UTypes > bool operator<=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (4) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator<=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (4) | (since C++14) |
template< class... TTypes, class... UTypes > bool operator>( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (5) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator>( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (5) | (since C++14) |
template< class... TTypes, class... UTypes > bool operator>=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (6) | (since C++11) (until C++14) |
template< class... TTypes, class... UTypes > constexpr bool operator>=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs | (6) | (since C++14) |
1-2%29比较元组的每个元素。lhs
与元组的对应元素。rhs
...
3-6%29比较lhs
和rhs
在词汇上,也就是说,比较第一个元素,如果它们是等价的,那么比较第二个元素,如果它们是等价的,那么比较第三个元素,等等。
所有的比较操作符都是短路的;它们不访问元组元素,而不访问确定比较结果所必需的内容。
参数
lhs, rhs | - | tuples to compare |
---|
返回值
1%29true如果std::get<i>(lhs) == std::get<i>(rhs)为了我的一切[0, sizeof...(Types)),否则false.对于两个空元组返回true...
2%29!(lhs == rhs)
...
3%29(bool)(std::get<0>(lhs) < std::get<0>(rhs)) || (!(bool)(std::get<0>(rhs) < std::get<0>(lhs)) && lhstail < rhstail),在哪里lhstail是LHS没有第一个元素,而且rhstail是没有第一个元素的RHS。对于两个空元组,返回false...
4%29!(rhs < lhs)...
5%29rhs < lhs...
6%29!(lhs < rhs)...
例
因为运算符<是为元组定义的,所以可以对元组的容器进行排序。
二次
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::tuple<int, std::string, float>> v;
v.emplace_back(2, "baz", -0.1
v.emplace_back(2, "bar", 3.14
v.emplace_back(1, "foo", 100.1
std::sort(v.begin(), v.end()
for(auto p: v) {
std::cout << "(" << std::get<0>(p) << ", " << std::get<1>(p)
<< ", " << std::get<2>(p) << ")\n";
}
}
二次
产出:
二次
(1, foo, 100.1)
(2, bar, 3.14)
(2, baz, -0.1)
二次
另见
二次
*。
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。