From: Marshall Clow Date: Thu, 2 Aug 2018 02:11:06 +0000 (+0000) Subject: Implement P1023: constexpr comparison operators for std::array X-Git-Tag: llvmorg-8.0.0-rc1~11939 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07d8ac0ab554286e080ba8b0433f71982253342d;p=platform%2Fupstream%2Fllvm.git Implement P1023: constexpr comparison operators for std::array llvm-svn: 338668 --- diff --git a/libcxx/include/array b/libcxx/include/array index 1e6a650..ba4ff42 100644 --- a/libcxx/include/array +++ b/libcxx/include/array @@ -367,7 +367,7 @@ array(_Tp, _Args...) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); @@ -375,7 +375,7 @@ operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__x == __y); @@ -383,7 +383,7 @@ operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return _VSTD::lexicographical_compare(__x.begin(), __x.end(), @@ -392,7 +392,7 @@ operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return __y < __x; @@ -400,7 +400,7 @@ operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__y < __x); @@ -408,7 +408,7 @@ operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) template inline _LIBCPP_INLINE_VISIBILITY -bool +_LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) { return !(__x < __y); diff --git a/libcxx/test/std/containers/sequences/array/compare.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.pass.cpp index c8bcf75..f3e72b7 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 @@ // +// These are all constexpr in C++20 // bool operator==(array const&, array const&); // bool operator!=(array const&, array const&); // bool operator<(array const&, array 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 +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 a1 = {1, 2, 3}; + constexpr std::array 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 } diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html index fc69b29..fa6a47a3 100644 --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -72,7 +72,7 @@ P0767R1CWGDeprecate PODAlbuquerqueComplete7.0 P0768R1CWGLibrary Support for the Spaceship (Comparison) OperatorAlbuquerque P0777R1LWGTreating Unnecessary decayAlbuquerqueComplete7.0 - P0122R7LWG<span>JacksonvilleComplete7.0 + P0122R7LWG<span>JacksonvilleComplete7.0 P0355R7LWGExtending chrono to Calendars and Time ZonesJacksonville P0551R3LWGThou Shalt Not Specialize std Function Templates!Jacksonville P0753R2LWGManipulators for C++ Synchronized Buffered OstreamJacksonville @@ -98,12 +98,12 @@ P0769R2LWGAdd shift to <algorithm>Rapperswil P0788R3LWGStandard Library Specification in a Concepts and Contracts WorldRapperswil P0879R0LWGConstexpr for swap and swap related functions Also resolves LWG issue 2800.Rapperswil - P0887R1LWGThe identity metafunctionRapperswil + P0887R1LWGThe identity metafunctionRapperswilComplete8.0 P0892R2CWGexplicit(bool)Rapperswil P0898R3LWGStandard Library ConceptsRapperswil P0935R0LWGEradicating unnecessarily explicit default constructors from the standard libraryRapperswil P0941R2CWGIntegrating feature-test macros into the C++ WDRapperswil - P1023R0LWGconstexpr comparison operators for std::arrayRapperswil + P1023R0LWGconstexpr comparison operators for std::arrayRapperswilComplete8.0 P1025R1CWGUpdate The Reference To The Unicode StandardRapperswil P1120R0CWGConsistency improvements for <=> and other comparison operatorsRapperswil @@ -222,7 +222,7 @@ -

Last Updated: 23-Jul-2018

+

Last Updated: 1-Aug-2018