C++ Tuple Library - relational operators (tuple)



Description

It contains relational operators for tuple and performs the appropriate comparison operation between the tuple objects lhs and rhs.

Declaration

Following is the declaration for std::relational operators (tuple)

C++98

	
template<class... TTypes, class... UTypes>
   bool operator== ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator!= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator< ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator> ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator>= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator<= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);

C++11

template<class... TTypes, class... UTypes>
   bool operator== ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator!= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator< ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator> ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator>= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
template<class... TTypes, class... UTypes>
   bool operator<= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
</pre>

Parameters

lhs, rhs − These are tuple objects.

Return Value

It returns true if the condition holds, and false otherwise.

Exceptions

No-throw guarantee − this member function never throws exceptions.

Data races

lhs and rhs, are accessed, and up to all of its members are accessed.

Example

In below example for std::relational operators (tuple).

#include <iostream>
#include <tuple>

int main () {
   std::tuple<int,char> a (100,'x');
   std::tuple<char,char> b (100,'x');
   std::tuple<char,char> c (100,'y');

   if (a==b) std::cout << "a and b are equal\n";
   if (b!=c) std::cout << "b and c are not equal\n";
   if (b<c) std::cout << "b is less than c\n";
   if (c>a) std::cout << "c is greater than a\n";
   if (a<=c) std::cout << "a is less than or equal to c\n";
   if (c>=b) std::cout << "c is greater than or equal to b\n";

   return 0;
}

The output should be like this −

a and b are equal
b and c are not equal
b is less than c
c is greater than a
a is less than or equal to c
c is greater than or equal to b
tuple.htm
Advertisements