Implement LWG-3785 `ranges::to` is over-constrained on the destination type being a range (#3319)

This commit is contained in:
A. Jiang 2023-01-12 09:09:43 +08:00 коммит произвёл GitHub
Родитель 9c3aeb2dfa
Коммит a71aa5259e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -7668,7 +7668,8 @@ namespace ranges {
// clang-format on
template <class _Rng, class _Container>
concept _Ref_converts = convertible_to<range_reference_t<_Rng>, range_value_t<_Container>>;
concept _Ref_converts =
(!input_range<_Container>) || convertible_to<range_reference_t<_Rng>, range_value_t<_Container>>;
template <class _Rng, class _Container, class... _Types>
concept _Converts_direct_constructible = _Ref_converts<_Rng, _Container> //

Просмотреть файл

@ -3,6 +3,7 @@
#include <cassert>
#include <cstddef>
#include <optional>
#include <ranges>
#include <vector>
@ -136,6 +137,28 @@ constexpr bool test_nested_range() {
return true;
}
constexpr bool test_lwg3785() {
std::vector<int> vec{42, 1729};
auto expe1 = ranges::to<std::optional<std::vector<int>>>(vec);
assert(expe1.has_value());
assert(*expe1 == vec);
auto expe2 = vec | ranges::to<std::optional<std::vector<int>>>();
assert(expe2.has_value());
assert(*expe2 == vec);
auto expe3 = ranges::to<std::optional>(vec);
assert(expe3.has_value());
assert(*expe3 == vec);
auto expe4 = vec | ranges::to<std::optional>();
assert(expe4.has_value());
assert(*expe4 == vec);
return true;
}
int main() {
test_reservable();
static_assert(test_reservable());
@ -147,4 +170,7 @@ int main() {
#if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-1588614
static_assert(test_nested_range());
#endif // defined(__clang__) || defined(__EDG__)
test_lwg3785();
static_assert(test_lwg3785());
}