--- description: "Learn more about: operators" title: " operators" ms.date: "11/04/2016" f1_keywords: ["array/std::array::operator!=", "array/std::array::operator<", "array/std::array::operator<=", "array/std::array::operator>", "array/std::array::operator>=", "array/std::array::operator=="] ms.assetid: c8f46282-f179-4909-9a01-639cb8e18c27 --- # `` operators The \ header includes these **array** non-member comparison template functions. [operator!=](#op_neq)\ [`operator>`](#op_gt)\ [`operator>=`](#op_gt_eq)\ [`operator<`](#op_lt)\ [`operator<=`](#op_lt_eq)\ [operator==](#op_eq_eq) ## operator!= Array comparison, not equal. ```cpp template bool operator!=( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function returns `!(left == right)`. ### Example ```cpp // std__array__operator_ne.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 != c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c0 != c1); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 false true ``` ## `operator<` Array comparison, less than. ```cpp template bool operator<( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function overloads `operator<` to compare two objects of class template [array Class](../standard-library/array-class-stl.md). The function returns `lexicographical_compare(left.begin(), left.end(), right.begin())`. ### Example ```cpp // std__array__operator_lt.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 < c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c0 < c1); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 false true ``` ## `operator<=` Array comparison, less than or equal. ```cpp template bool operator<=( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function returns `!(right < left)`. ### Example ```cpp // std__array__operator_le.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 <= c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c1 <= c0); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 true false ``` ## operator== Array comparison, equal. ```cpp template bool operator==( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function overloads `operator==` to compare two objects of class template [array Class](../standard-library/array-class-stl.md). The function returns `equal(left.begin(), left.end(), right.begin())`. ### Example ```cpp // std__array__operator_eq.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 == c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c0 == c1); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 true false ``` ## `operator>` Array comparison, greater than. ```cpp template bool operator>( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function returns `(right < left)`. ### Example ```cpp // std__array__operator_gt.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 > c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c1 > c0); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 false true ``` ## `operator>=` Array comparison, greater than or equal. ```cpp template bool operator>=( const array& left, const array& right); ``` ### Parameters *Ty*\ The type of an element. *N*\ The size of the array. *left*\ Left container to compare. *right*\ Right container to compare. ### Remarks The template function returns `!(left < right)`. ### Example ```cpp // std__array__operator_ge.cpp // compile with: /EHsc #include #include typedef std::array Myarray; int main() { Myarray c0 = {0, 1, 2, 3}; // display contents " 0 1 2 3" for (Myarray::const_iterator it = c0.begin(); it != c0.end(); ++it) std::cout << " " << *it; std::cout << std::endl; Myarray c1 = {4, 5, 6, 7}; // display contents " 4 5 6 7" for (Myarray::const_iterator it = c1.begin(); it != c1.end(); ++it) std::cout << " " << *it; std::cout << std::endl; // display results of comparisons std::cout << std::boolalpha << " " << (c0 >= c0); std::cout << std::endl; std::cout << std::boolalpha << " " << (c0 >= c1); std::cout << std::endl; return (0); } ``` ```Output 0 1 2 3 4 5 6 7 true false ``` ## See also [\](../standard-library/array.md)