|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef _LIBCPP___VECTOR_COMPARISON_H |
| 10 | +#define _LIBCPP___VECTOR_COMPARISON_H |
| 11 | + |
| 12 | +#include <__algorithm/equal.h> |
| 13 | +#include <__algorithm/lexicographical_compare.h> |
| 14 | +#include <__algorithm/lexicographical_compare_three_way.h> |
| 15 | +#include <__compare/synth_three_way.h> |
| 16 | +#include <__config> |
| 17 | +#include <__fwd/vector.h> |
| 18 | + |
| 19 | +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 | +# pragma GCC system_header |
| 21 | +#endif |
| 22 | + |
| 23 | +_LIBCPP_BEGIN_NAMESPACE_STD |
| 24 | + |
| 25 | +template <class _Tp, class _Allocator> |
| 26 | +_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool |
| 27 | +operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 28 | + const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); |
| 29 | + return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); |
| 30 | +} |
| 31 | + |
| 32 | +#if _LIBCPP_STD_VER <= 17 |
| 33 | + |
| 34 | +template <class _Tp, class _Allocator> |
| 35 | +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 36 | + return !(__x == __y); |
| 37 | +} |
| 38 | + |
| 39 | +template <class _Tp, class _Allocator> |
| 40 | +inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 41 | + return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
| 42 | +} |
| 43 | + |
| 44 | +template <class _Tp, class _Allocator> |
| 45 | +inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 46 | + return __y < __x; |
| 47 | +} |
| 48 | + |
| 49 | +template <class _Tp, class _Allocator> |
| 50 | +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 51 | + return !(__x < __y); |
| 52 | +} |
| 53 | + |
| 54 | +template <class _Tp, class _Allocator> |
| 55 | +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 56 | + return !(__y < __x); |
| 57 | +} |
| 58 | + |
| 59 | +#else // _LIBCPP_STD_VER <= 17 |
| 60 | + |
| 61 | +template <class _Tp, class _Allocator> |
| 62 | +_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp> |
| 63 | +operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { |
| 64 | + return std::lexicographical_compare_three_way( |
| 65 | + __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); |
| 66 | +} |
| 67 | + |
| 68 | +#endif // _LIBCPP_STD_VER <= 17 |
| 69 | + |
| 70 | +_LIBCPP_END_NAMESPACE_STD |
| 71 | + |
| 72 | +#endif // _LIBCPP___VECTOR_COMPARISON_H |
0 commit comments