Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -8388,7 +8388,8 @@ namespace ranges {
template <class _Rng, class _Container, class... _Types>
concept _Converts_and_common_constructible =
_Ref_converts<_Rng, _Container> && common_range<_Rng> //
&& _Cpp17_input_iterator<iterator_t<_Rng>> //
&& requires { typename iterator_traits<iterator_t<_Rng>>::iterator_category; }
&& derived_from<typename iterator_traits<iterator_t<_Rng>>::iterator_category, input_iterator_tag>
&& constructible_from<_Container, iterator_t<_Rng>, iterator_t<_Rng>, _Types...>;

template <class _Container, class _Reference>
Expand Down
24 changes: 24 additions & 0 deletions tests/std/tests/P1206R7_ranges_to_misc/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ constexpr bool test_nested_range() {
return true;
}

struct ContainerLike {
template <std::input_iterator Iter>
constexpr ContainerLike(Iter first, Iter last) : dist(static_cast<std::ptrdiff_t>(ranges::distance(first, last))) {}

constexpr char* begin() {
return nullptr;
}
constexpr char* end() {
return nullptr;
}

std::ptrdiff_t dist;
};

constexpr bool test_lwg3733() {
auto nul_termination = std::views::take_while([](char ch) { return ch != '\0'; });
auto c = nul_termination("1729") | std::views::common | ranges::to<ContainerLike>();
assert(c.dist == 4);
return true;
}

constexpr bool test_lwg3785() {
std::vector<int> vec{42, 1729};

Expand Down Expand Up @@ -171,6 +192,9 @@ int main() {
static_assert(test_nested_range());
#endif // defined(__clang__) || defined(__EDG__)

test_lwg3733();
static_assert(test_lwg3733());

test_lwg3785();
static_assert(test_lwg3785());
}