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-3743 ranges::to's reserve may be ill-formed #3269

Merged
merged 8 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -7588,7 +7588,7 @@ namespace ranges {
} else if constexpr (_Converts_constructible_insertable<_Rng, _Container, _Types...>) {
_Container _Cont(_STD forward<_Types>(_Args)...);
if constexpr (_Sized_and_reservable<_Rng, _Container>) {
_Cont.reserve(_RANGES size(_Range));
_Cont.reserve(static_cast<range_size_t<_Container>>(_RANGES size(_Range)));
}
_RANGES copy(_Range, _Container_inserter<range_reference_t<_Rng>>(_Cont));
return _Cont;
Expand Down
3 changes: 3 additions & 0 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,8 @@ namespace ranges {
constexpr explicit _Subrange_base(const _Size_type&) noexcept {}
};

#pragma warning(push)
#pragma warning(disable : 4324) // structure was padded due to alignment specifier
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
_EXPORT_STD template <input_or_output_iterator _It, sentinel_for<_It> _Se, subrange_kind _Ki>
requires (_Ki == subrange_kind::sized || !sized_sentinel_for<_Se, _It>)
class subrange : public _Subrange_base<_It, _Se, _Ki> {
Expand Down Expand Up @@ -3760,6 +3762,7 @@ namespace ranges {
return *this;
}
};
#pragma warning(pop)

template <input_or_output_iterator _It, sentinel_for<_It> _Se>
subrange(_It, _Se) -> subrange<_It, _Se>;
Expand Down
6 changes: 6 additions & 0 deletions tests/std/tests/P1206R7_vector_from_range/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ void test_vso1591034() {
assert(counted_item::count == 6);
}

void test_LWG_3743() { // COMPILE-ONLY
ranges::take_view t = views::iota(0ULL) | views::take(5);
ranges::subrange r = ranges::subrange(t, 5);
[[maybe_unused]] vector v = r | ranges::to<vector<unsigned long long>>(size_t{0});
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
}

int main() {
// Validate views
test_copyable_views();
Expand Down