Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constexpr for std::array Comparisons #599

Merged
merged 18 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -380,32 +380,32 @@ void swap(array<_Ty, _Size>& _Left, array<_Ty, _Size>& _Right) noexcept(noexcept
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator==(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator==(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
return _STD equal(_Left.begin(), _Left.end(), _Right.begin());
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator!=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator!=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
return !(_Left == _Right);
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator<(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator<(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
return _STD lexicographical_compare(_Left.begin(), _Left.end(), _Right.begin(), _Right.end());
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator>(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator>(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
return _Right < _Left;
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator<=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator<=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
return !(_Right < _Left);
}

template <class _Ty, size_t _Size>
_NODISCARD bool operator>=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
_NODISCARD _CONSTEXPR20 bool operator>=(const array<_Ty, _Size>& _Left, const array<_Ty, _Size>& _Right) {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
return !(_Left < _Right);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
8 changes: 7 additions & 1 deletion stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
// P0919R3 Heterogeneous Lookup For Unordered Containers
// P0966R1 string::reserve() Should Not Shrink
// P1006R1 constexpr For pointer_traits<T*>::pointer_to()
// P1023R0 constexpr For std::array Comparisons
// P1024R3 Enhancing span Usability
// P1085R2 Removing span Comparisons
// P1115R3 erase()/erase_if() Return size_type
Expand Down Expand Up @@ -1037,7 +1038,6 @@
#if _HAS_CXX17
#define __cpp_lib_any 201606L
#define __cpp_lib_apply 201603L
#define __cpp_lib_array_constexpr 201803L
#define __cpp_lib_atomic_is_always_lock_free 201603L
#define __cpp_lib_boyer_moore_searcher 201603L
#if _HAS_STD_BYTE
Expand Down Expand Up @@ -1127,6 +1127,12 @@
#define __cpp_lib_unwrap_ref 201811L
#endif // _HAS_CXX20

#if _HAS_CXX20
#define __cpp_lib_array_constexpr 201806L // P1023R0 constexpr For std::array Comparisons
#elif _HAS_CXX17 // ^^^ _HAS_CXX20 / _HAS_CXX17 vvv
#define __cpp_lib_array_constexpr 201803L
#endif // _HAS_CXX17

// EXPERIMENTAL
#define __cpp_lib_experimental_erase_if 201411L
#define __cpp_lib_experimental_filesystem 201406L
Expand Down
3 changes: 0 additions & 3 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,6 @@ std/language.support/support.limits/support.limits.general/functional.version.pa
std/language.support/support.limits/support.limits.general/iterator.version.pass.cpp SKIP
std/language.support/support.limits/support.limits.general/memory.version.pass.cpp SKIP

# C++20 P1023R0 "constexpr For std::array Comparisons"
std/containers/sequences/array/compare.pass.cpp SKIP

# C++20 P1032R1 "Miscellaneous constexpr"
std/language.support/support.limits/support.limits.general/array.version.pass.cpp SKIP
std/language.support/support.limits/support.limits.general/functional.version.pass.cpp SKIP
Expand Down
3 changes: 0 additions & 3 deletions tests/libcxx/skipped_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,6 @@ language.support\support.limits\support.limits.general\functional.version.pass.c
language.support\support.limits\support.limits.general\iterator.version.pass.cpp
language.support\support.limits\support.limits.general\memory.version.pass.cpp

# C++20 P1023R0 "constexpr For std::array Comparisons"
containers\sequences\array\compare.pass.cpp
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

# C++20 P1032R1 "Miscellaneous constexpr"
language.support\support.limits\support.limits.general\array.version.pass.cpp
language.support\support.limits\support.limits.general\functional.version.pass.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ tests\P0898R3_concepts
tests\P0898R3_identity
tests\P0919R3_heterogeneous_unordered_lookup
tests\P0966R1_string_reserve_should_not_shrink
tests\P1023R0_constexpr_for_array_comparisons
tests\P1165R1_consistently_propagating_stateful_allocators
tests\P1423R3_char8_t_remediation
tests\P1645R1_constexpr_numeric
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_latest_matrix.lst
71 changes: 71 additions & 0 deletions tests/std/tests/P1023R0_constexpr_for_array_comparisons/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <array>
#include <cassert>

using namespace std;

constexpr array<int, 5> a0{{2, 8, 9, 1, 9}};
constexpr array<int, 3> a1{{2, 8, 9}};
constexpr array<int, 5> a2{{2, 8, 9, 1, 8}};
constexpr array<int, 0> a3{};

constexpr void test_operator_eq() {
assert(a0 == a0);
assert(a1 == a1);
assert(!(a0 == a2));
assert(a3 == a3);
}

constexpr void test_operator_neq() {
assert(!(a0 != a0));
assert(!(a1 != a1));
assert(a0 != a2);
assert(!(a3 != a3));
}

constexpr void test_operator_lt() {
assert(!(a0 < a0));
assert(!(a1 < a1));
assert(a2 < a0);
assert(!(a3 < a3));
}

constexpr void test_operator_gt() {
assert(!(a0 > a0));
assert(!(a1 > a1));
assert(a0 > a2);
assert(!(a3 > a3));
}


constexpr void test_operator_leq() {
assert(a0 <= a0);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(a1 <= a1);
assert(a2 <= a0);
assert(a3 <= a3);
}


constexpr void test_operator_geq() {
assert(a0 >= a0);
assert(a1 >= a1);
assert(a0 >= a2);
assert(a3 >= a3);
}

constexpr bool test() {
test_operator_eq();
test_operator_neq();
test_operator_lt();
test_operator_gt();
test_operator_leq();
test_operator_geq();
return true;
}

int main() {
test();
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
static_assert(test());
}
10 changes: 9 additions & 1 deletion tests/std/tests/VSO_0157762_feature_test_macros/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,15 @@ STATIC_ASSERT(__cpp_lib_apply == 201603L);
#endif
#endif

#if _HAS_CXX17
#if _HAS_CXX20
#ifndef __cpp_lib_array_constexpr
#error __cpp_lib_array_constexpr is not defined
#elif __cpp_lib_array_constexpr != 201806L
#error __cpp_lib_array_constexpr is not 201806L
#else
STATIC_ASSERT(__cpp_lib_array_constexpr == 201806L);
#endif
#elif _HAS_CXX17
#ifndef __cpp_lib_array_constexpr
#error __cpp_lib_array_constexpr is not defined
#elif __cpp_lib_array_constexpr != 201803L
Expand Down