diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2018-08-02 02:11:06 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2018-08-02 02:11:06 +0000 |
| commit | 07d8ac0ab554286e080ba8b0433f71982253342d (patch) | |
| tree | 10b76e6939b2fe11b1d31ea4626385468574b8da /libcxx/test/std/containers/sequences/array/compare.pass.cpp | |
| parent | 1d08c51ee56d25a360adb8005205445cd09854ca (diff) | |
| download | bcm5719-llvm-07d8ac0ab554286e080ba8b0433f71982253342d.tar.gz bcm5719-llvm-07d8ac0ab554286e080ba8b0433f71982253342d.zip | |
Implement P1023: constexpr comparison operators for std::array
llvm-svn: 338668
Diffstat (limited to 'libcxx/test/std/containers/sequences/array/compare.pass.cpp')
| -rw-r--r-- | libcxx/test/std/containers/sequences/array/compare.pass.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/array/compare.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.pass.cpp index c8bcf75a093..f3e72b79fa0 100644 --- a/libcxx/test/std/containers/sequences/array/compare.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/compare.pass.cpp @@ -9,6 +9,7 @@ // <array> +// These are all constexpr in C++20 // bool operator==(array<T, N> const&, array<T, N> const&); // bool operator!=(array<T, N> const&, array<T, N> const&); // bool operator<(array<T, N> const&, array<T, N> const&); @@ -40,6 +41,41 @@ void test_compare(const Array& LHS, const Array& RHS) { assert((LHS >= RHS) == (LHSV >= RHSV)); } +#if TEST_STD_VER > 17 +template <class Array> +constexpr bool constexpr_compare(const Array &lhs, const Array &rhs, bool isEqual, bool isLess) +{ + if (isEqual) + { + if (!(lhs == rhs)) return false; + if ( (lhs != rhs)) return false; + if ( (lhs < rhs)) return false; + if (!(lhs <= rhs)) return false; + if ( (lhs > rhs)) return false; + if (!(lhs >= rhs)) return false; + } + else if (isLess) + { + if ( (lhs == rhs)) return false; + if (!(lhs != rhs)) return false; + if (!(lhs < rhs)) return false; + if (!(lhs <= rhs)) return false; + if ( (lhs > rhs)) return false; + if ( (lhs >= rhs)) return false; + } + else // greater + { + if ( (lhs == rhs)) return false; + if (!(lhs != rhs)) return false; + if ( (lhs < rhs)) return false; + if ( (lhs <= rhs)) return false; + if (!(lhs > rhs)) return false; + if (!(lhs >= rhs)) return false; + } + return true; +} +#endif + int main() { { @@ -60,4 +96,14 @@ int main() C c2 = {}; test_compare(c1, c2); } + +#if TEST_STD_VER > 17 + { + constexpr std::array<int, 3> a1 = {1, 2, 3}; + constexpr std::array<int, 3> a2 = {2, 3, 4}; + static_assert(constexpr_compare(a1, a1, true, false), ""); + static_assert(constexpr_compare(a1, a2, false, true), ""); + static_assert(constexpr_compare(a2, a1, false, false), ""); + } +#endif } |

