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 P2328R1 join_view Should Join All Views Of Ranges #2038

Merged
merged 22 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
92ce96e
Implement P2328R1 join_view should join all ranges
miscco Jul 2, 2021
49bf9a3
Specialize `_Non_propagating_cache` and fix test
miscco Jul 3, 2021
5e74f42
More tests
miscco Jul 3, 2021
8041fc4
We should rela test requirements
miscco Jul 3, 2021
351f538
More test coverage and internal testing
miscco Jul 4, 2021
72f392c
Address more review comments
miscco Jul 6, 2021
e283371
Properly destroy existing element in _Emplace_deref
miscco Jul 15, 2021
f546493
Further simplify _Non_propagating_cache for trivially_destructible types
miscco Jul 15, 2021
c2bc106
More review comments
miscco Jul 18, 2021
7b426da
Require `is_default_constructible_v` for the specialization of `_Non_…
miscco Jul 18, 2021
36cd233
Merge branch 'main' into P2328-join-view
miscco Jul 20, 2021
11f44fa
Use _CONSTEXPR20
miscco Jul 20, 2021
03c80bc
Update tests
miscco Jul 21, 2021
48ee23a
Merge branch 'main' into P2328-join-view
miscco Aug 4, 2021
317fe66
Address review comments
miscco Aug 4, 2021
2075c52
Update tests/std/tests/P0896R4_views_join/test.cpp
CaseyCarter Aug 4, 2021
3787596
Remove "dummy" union members not needed for C++20
CaseyCarter Aug 5, 2021
f9a7a6a
Enable join_view to handle immovable types
miscco Aug 5, 2021
52d36e1
Merge branch 'main' into P2328-join-view
miscco Aug 6, 2021
0c54f03
Hijack the `_Not_quite_object::_Construct_tag` to avoid conversions
miscco Aug 6, 2021
b3925ac
Remove unnecessary `const` on a nameless value parameter.
StephanTLavavej Aug 6, 2021
4a7ba61
Remove `|| defined(MSVC_INTERNAL_TESTING)`.
StephanTLavavej Aug 9, 2021
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
23 changes: 15 additions & 8 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,14 @@ namespace ranges {
return _Val;
}

template <class _It>
constexpr _Ty& _Emplace_deref(_It& _Iter) noexcept(
is_nothrow_constructible_v<_Ty, iter_reference_t<_It>>) /* strengthened */ {
template <class... _Types>
constexpr _Ty& _Emplace(_Types&&... _Args) noexcept(is_nothrow_constructible_v<_Ty, _Types...>) {
if (_Engaged) {
_Val.~_Ty();
_Engaged = false;
}

_Construct_in_place(_Val, *_Iter);
_Construct_in_place(_Val, _STD forward<_Types>(_Args)...);
_Engaged = true;

return _Val;
Expand Down Expand Up @@ -2962,8 +2961,16 @@ namespace ranges {

template <class _Vw>
class _Join_view_base : public view_interface<join_view<_Vw>> {
private:
struct _Cache_wrapper {
template <input_iterator _Iter>
constexpr _Cache_wrapper(const _Iter& _It) noexcept(noexcept(*_It)) : _Val(*_It) {}
miscco marked this conversation as resolved.
Show resolved Hide resolved

remove_cv_t<range_reference_t<_Vw>> _Val;
};

protected:
/* [[no_unique_address]] */ _Non_propagating_cache<remove_cv_t<range_reference_t<_Vw>>> _Inner{};
/* [[no_unique_address]] */ _Non_propagating_cache<_Cache_wrapper> _Inner{};
};

// clang-format off
Expand Down Expand Up @@ -3033,7 +3040,7 @@ namespace ranges {
if constexpr (_Deref_is_glvalue) {
return *_Outer;
} else {
return _Parent->_Inner._Emplace_deref(_Outer);
return _Parent->_Inner._Emplace(_Outer)._Val;
}
}

Expand All @@ -3059,7 +3066,7 @@ namespace ranges {
if constexpr (_Deref_is_glvalue) {
_Last = _RANGES end(*_Outer);
} else {
_Last = _RANGES end(*_Parent->_Inner);
_Last = _RANGES end((*_Parent->_Inner)._Val);
}
_STL_VERIFY(_Inner && *_Inner != _Last, "cannot dereference join_view end iterator");
}
Expand Down Expand Up @@ -3127,7 +3134,7 @@ namespace ranges {
_Satisfy();
}
} else {
if (++*_Inner == _RANGES end(*_Parent->_Inner)) {
if (++*_Inner == _RANGES end((*_Parent->_Inner)._Val)) {
++_Outer;
_Satisfy();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/std/tests/P0896R4_views_join/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ constexpr auto ToString(const size_t val) {
return string{prvalue_input[val]};
}

struct Immovable {
Immovable() = default;
Immovable(const Immovable&) = delete;
Immovable(Immovable&&) = delete;
Immovable& operator=(const Immovable&) = delete;
Immovable& operator=(Immovable&&) = delete;
};

int main() {
// Validate views
constexpr string_view expected = "Hello World!"sv;
Expand Down Expand Up @@ -556,6 +564,12 @@ int main() {
#endif // not MSVC
}

miscco marked this conversation as resolved.
Show resolved Hide resolved
{ // Immovable type
auto ToArrayOfImmovable = [](const int) { return array<Immovable, 3>{}; };
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
assert(ranges::distance(views::iota(0, 2) | views::transform(ToArrayOfImmovable) | views::join) == 6);
static_assert(ranges::distance(views::iota(0, 2) | views::transform(ToArrayOfImmovable) | views::join) == 6);
}

STATIC_ASSERT(instantiation_test());
instantiation_test();
}