forked from OSchip/llvm-project
Implement P1023: constexpr comparison operators for std::array
llvm-svn: 338668
This commit is contained in:
parent
1d08c51ee5
commit
07d8ac0ab5
|
@ -367,7 +367,7 @@ array(_Tp, _Args...)
|
|||
|
||||
template <class _Tp, size_t _Size>
|
||||
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 <class _Tp, size_t _Size>
|
||||
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 <class _Tp, size_t _Size>
|
||||
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 <class _Tp, size_t _Size>
|
||||
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 <class _Tp, size_t _Size>
|
||||
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 <class _Tp, size_t _Size>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
bool
|
||||
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
|
||||
operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
|
||||
{
|
||||
return !(__x < __y);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<tr><td><a href="https://wg21.link/P0767R1">P0767R1</a></td><td>CWG</td><td>Deprecate POD</td><td>Albuquerque</td><td>Complete</td><td>7.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0768R1">P0768R1</a></td><td>CWG</td><td>Library Support for the Spaceship (Comparison) Operator</td><td>Albuquerque</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0777R1">P0777R1</a></td><td>LWG</td><td>Treating Unnecessary <tt>decay</tt></td><td>Albuquerque</td><td>Complete</td><td>7.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0122R7">P0122R7</a></td><td>LWG</td><td><span></td><td>Jacksonville</td><td><i>Complete</i></td><td>7.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0122R7">P0122R7</a></td><td>LWG</td><td><span></td><td>Jacksonville</td><td>Complete</td><td>7.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0355R7">P0355R7</a></td><td>LWG</td><td>Extending chrono to Calendars and Time Zones</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0551R3">P0551R3</a></td><td>LWG</td><td>Thou Shalt Not Specialize <tt>std</tt> Function Templates!</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0753R2">P0753R2</a></td><td>LWG</td><td>Manipulators for C++ Synchronized Buffered Ostream</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||
|
@ -98,12 +98,12 @@
|
|||
<tr><td><a href="https://wg21.link/P0769R2">P0769R2</a></td><td>LWG</td><td>Add shift to <algorithm></td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0788R3">P0788R3</a></td><td>LWG</td><td>Standard Library Specification in a Concepts and Contracts World</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0879R0">P0879R0</a></td><td>LWG</td><td>Constexpr for swap and swap related functions Also resolves LWG issue 2800.</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0887R1">P0887R1</a></td><td>LWG</td><td>The identity metafunction</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0887R1">P0887R1</a></td><td>LWG</td><td>The identity metafunction</td><td>Rapperswil</td><td>Complete</td><td>8.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0892R2">P0892R2</a></td><td>CWG</td><td>explicit(bool)</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0898R3">P0898R3</a></td><td>LWG</td><td>Standard Library Concepts</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0935R0">P0935R0</a></td><td>LWG</td><td>Eradicating unnecessarily explicit default constructors from the standard library</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0941R2">P0941R2</a></td><td>CWG</td><td>Integrating feature-test macros into the C++ WD</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P1023R0">P1023R0</a></td><td>LWG</td><td>constexpr comparison operators for std::array</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P1023R0">P1023R0</a></td><td>LWG</td><td>constexpr comparison operators for std::array</td><td>Rapperswil</td><td>Complete</td><td>8.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P1025R1">P1025R1</a></td><td>CWG</td><td>Update The Reference To The Unicode Standard</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P1120R0">P1120R0</a></td><td>CWG</td><td>Consistency improvements for <=> and other comparison operators</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
|
||||
|
@ -222,7 +222,7 @@
|
|||
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
|
||||
</table>
|
||||
|
||||
<p>Last Updated: 23-Jul-2018</p>
|
||||
<p>Last Updated: 1-Aug-2018</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue