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

Implement LWG-3590: split_view::base() const & is overconstrained #2404

Merged
merged 5 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -3962,7 +3962,7 @@ namespace ranges {
// clang-format on

_NODISCARD constexpr _Vw base() const& noexcept(is_nothrow_copy_constructible_v<_Vw>) /* strengthened */
requires copyable<_Vw> {
requires copy_constructible<_Vw> {
return _Range;
}
_NODISCARD constexpr _Vw base() && noexcept(is_nothrow_move_constructible_v<_Vw>) /* strengthened */ {
Expand Down
30 changes: 30 additions & 0 deletions tests/std/tests/P0896R4_views_split/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <cassert>
#include <charconv>
#include <concepts>
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
#include <ranges>
#include <span>
#include <string_view>
Expand Down Expand Up @@ -328,6 +329,32 @@ constexpr bool test_devcom_1559808() {
return true;
}

struct CopyConstructibleRange {
constexpr explicit CopyConstructibleRange(vector<int> v) : inner(move(v)) {}
CopyConstructibleRange(const CopyConstructibleRange&) = default;
CopyConstructibleRange& operator=(const CopyConstructibleRange&) = delete;
constexpr const int* begin() const {
return inner.data();
}
constexpr const int* end() const {
return inner.data() + inner.size();
}

vector<int> inner;
};

constexpr bool test_LWG_3590() {
CopyConstructibleRange r{{1, 2, 3, 4}};
const auto split_view = views::split(r, 0);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

STATIC_ASSERT(copy_constructible<CopyConstructibleRange>);
STATIC_ASSERT(!copyable<CopyConstructibleRange>);

const auto ref_view = split_view.base();
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

return ref_view.base().inner == r.inner;
}

int main() {
STATIC_ASSERT(instantiation_test());
instantiation_test();
Expand All @@ -336,4 +363,7 @@ int main() {
STATIC_ASSERT(test_devcom_1559808());
#endif // TRANSITION, DevCom-1516290
test_devcom_1559808();

STATIC_ASSERT(test_LWG_3590());
assert(test_LWG_3590());
}