operator==,!=,<,<=,>,>=(std::tuple) (3) - Linux Manuals
operator==,!=,<,<=,>,>=(std::tuple): operator==,!=,<,<=,>,>=(std::tuple)
Command to display operator==,!=,<,<=,>,>=(std::tuple)
manual in Linux: $ man 3 operator==,!=,<,<=,>,>=(std::tuple)
NAME
operator==,!=,<,<=,>,>=(std::tuple) - operator==,!=,<,<=,>,>=(std::tuple)
Synopsis
Defined in header <tuple>
template< class... TTypes, class... UTypes > (since C++11)
bool operator==( const tuple<TTypes...>& lhs, (1) (constexpr since C++14)
const tuple<UTypes...>& rhs );
template< class... TTypes, class... UTypes > (since C++11)
bool operator!=( const tuple<TTypes...>& lhs, (2) (constexpr since C++14)
const tuple<UTypes...>& rhs );
template< class... TTypes, class... UTypes > (since C++11)
bool operator<( const tuple<TTypes...>& lhs, (3) (constexpr since C++14)
const tuple<UTypes...>& rhs );
template< class... TTypes, class... UTypes > (since C++11)
bool operator<=( const tuple<TTypes...>& lhs, (4) (constexpr since C++14)
const tuple<UTypes...>& rhs );
template< class... TTypes, class... UTypes > (since C++11)
bool operator>( const tuple<TTypes...>& lhs, (5) (constexpr since C++14)
const tuple<UTypes...>& rhs );
template< class... TTypes, class... UTypes > (since C++11)
bool operator>=( const tuple<TTypes...>& lhs, (6) (constexpr since C++14)
const tuple<UTypes...>& rhs );
1-2) Compares every element of the tuple lhs with the corresponding element of the tuple rhs.
3-6) Compares lhs and rhs lexicographically, that is, compares the first elements, if they are equivalent, compares the second elements, if those are equivalent, compares the third elements, and so on.
All comparison operators are short-circuited; they do not access tuple elements beyond what is necessary to determine the result of the comparison.
Parameters
lhs, rhs - tuples to compare
Return value
1) true if std::get<i>(lhs) == std::get<i>(rhs) for all i in [0, sizeof...(Types)), otherwise false. For two empty tuples returns true.
2) !(lhs == rhs)
3) (bool)(std::get<0>(lhs) < std::get<0>(rhs)) || (!(bool)(std::get<0>(rhs) < std::get<0>(lhs)) && lhstail < rhstail), where lhstail is lhs without its first element, and rhstail is rhs without its first element. For two empty tuples, returns false.
4) !(rhs < lhs)
5) rhs < lhs
6) !(lhs < rhs)
Example
Because operator< is defined for tuples, containers of tuples can be sorted.
// Run this code
#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";
}
}
Output:
(1, foo, 100.1)
(2, bar, 3.14)
(2, baz, -0.1)
Pages related to operator==,!=,<,<=,>,>=(std::tuple)
- operator==,!=,<,<=,>,>=(std::thread::id) (3) - operator==,!=,<,<=,>,>=(std::thread::id)
- operator==,!=,<,<=,>,>=(std::time_point) (3) - operator==,!=,<,<=,>,>=(std::time_point)
- operator==,!=,<,<=,>,>=(std::array) (3) - operator==,!=,<,<=,>,>=(std::array)
- operator==,!=,<,<=,>,>=(std::basic_string) (3) - operator==,!=,<,<=,>,>=(std::basic_string)
- operator==,!=,<,<=,>,>=(std::basic_string_view) (3) - operator==,!=,<,<=,>,>=(std::basic_string_view)
- operator==,!=,<,<=,>,>=(std::chrono::duration) (3) - operator==,!=,<,<=,>,>=(std::chrono::duration)
- operator==,!=,<,<=,>,>=(std::deque) (3) - operator==,!=,<,<=,>,>=(std::deque)
- operator==,!=,<,<=,>,>=(std::experimental::basic_string_view) (3) - operator==,!=,<,<=,>,>=(std::experimental::basic_string_view)
- operator==,!=,<,<=,>,>=(std::experimental::filesystem::path) (3) - operator==,!=,<,<=,>,>=(std::experimental::filesystem::path)
- operator==,!=,<,<=,>,>=(std::experimental::observer_ptr) (3) - operator==,!=,<,<=,>,>=(std::experimental::observer_ptr)
- operator==,!=,<,<=,>,>=(std::experimental::optional) (3) - operator==,!=,<,<=,>,>=(std::experimental::optional)
- operator==,!=,<,<=,>,>=(std::experimental::propagate_const) (3) - operator==,!=,<,<=,>,>=(std::experimental::propagate_const)
- operator==,!=,<,<=,>,>=(std::filesystem::path) (3) - operator==,!=,<,<=,>,>=(std::filesystem::path)
- operator==,!=,<,<=,>,>=(std::forward_list) (3) - operator==,!=,<,<=,>,>=(std::forward_list)
- operator==,!=,<,<=,>,>=(std::list) (3) - operator==,!=,<,<=,>,>=(std::list)
- operator==,!=,<,<=,>,>=(std::map) (3) - operator==,!=,<,<=,>,>=(std::map)
- operator==,!=,<,<=,>,>=(std::multimap) (3) - operator==,!=,<,<=,>,>=(std::multimap)
- operator==,!=,<,<=,>,>=(std::multiset) (3) - operator==,!=,<,<=,>,>=(std::multiset)
- operator==,!=,<,<=,>,>=(std::optional) (3) - operator==,!=,<,<=,>,>=(std::optional)
- operator==,!=,<,<=,>,>=(std::pair) (3) - operator==,!=,<,<=,>,>=(std::pair)
- operator==,!=,<,<=,>,>=(std::queue) (3) - operator==,!=,<,<=,>,>=(std::queue)
- operator==,!=,<,<=,>,>=(std::set) (3) - operator==,!=,<,<=,>,>=(std::set)
- operator==,!=,<,<=,>,>=(std::stack) (3) - operator==,!=,<,<=,>,>=(std::stack)
- operator==,!=,<,<=,>,>=(std::sub_match) (3) - operator==,!=,<,<=,>,>=(std::sub_match)
- operator==,!=,<,<=,>,>=(std::unique_ptr) (3) - operator==,!=,<,<=,>,>=(std::unique_ptr)
- operator==,!=,<,<=,>,>=(std::valarray) (3) - operator==,!=,<,<=,>,>=(std::valarray)
- operator==,!=,<,<=,>,>=(std::variant) (3) - operator==,!=,<,<=,>,>=(std::variant)
- operator==,!=,<,<=,>,>=(std::vector) (3) - operator==,!=,<,<=,>,>=(std::vector)
- operator==,!=,<(std::error_condition) (3) - operator==,!=,<(std::error_condition)