From Jason Turner

[range.utility.conv.to]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmptn8k2igp/{from.md → to.md} +93 -0
tmp/tmptn8k2igp/{from.md → to.md} RENAMED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### `ranges::to` <a id="range.utility.conv.to">[[range.utility.conv.to]]</a>
2
+
3
+ ``` cpp
4
+ template<class C, input_range R, class... Args> requires (!view<C>)
5
+ constexpr C to(R&& r, Args&&... args);
6
+ ```
7
+
8
+ *Mandates:* `C` is a cv-unqualified class type.
9
+
10
+ *Returns:* An object of type `C` constructed from the elements of `r` in
11
+ the following manner:
12
+
13
+ - If `C` does not satisfy `input_range` or
14
+ `convertible_to<range_reference_t<R>, range_value_t<C>>` is `true`:
15
+ - If `constructible_from<C, R, Args...>` is `true`:
16
+ ``` cpp
17
+ C(std::forward<R>(r), std::forward<Args>(args)...)
18
+ ```
19
+ - Otherwise, if `constructible_from<C, from_range_t, R, Args...>` is
20
+ `true`:
21
+ ``` cpp
22
+ C(from_range, std::forward<R>(r), std::forward<Args>(args)...)
23
+ ```
24
+ - Otherwise, if
25
+ - `common_range<R>` is `true`,
26
+ - the *qualified-id*
27
+ `iterator_traits<iterator_t<R>>::iterator_category` is valid and
28
+ denotes a type that models `derived_from<input_iterator_tag>`, and
29
+ - `constructible_from<C, iterator_t<R>, sentinel_t<R>, Args...>` is
30
+ `true`:
31
+
32
+ ``` cpp
33
+ C(ranges::begin(r), ranges::end(r), std::forward<Args>(args)...)
34
+ ```
35
+ - Otherwise, if
36
+ - `constructible_from<C, Args...>` is `true`, and
37
+ - *`container-insertable`*`<C, range_reference_t<R>>` is `true`:
38
+
39
+ ``` cpp
40
+ C c(std::forward<Args>(args)...);
41
+ if constexpr (sized_range<R> && reservable-container<C>)
42
+ c.reserve(static_cast<range_size_t<C>>(ranges::size(r)));
43
+ ranges::copy(r, container-inserter<range_reference_t<R>>(c));
44
+ ```
45
+ - Otherwise, if `input_range<range_reference_t<R>>` is `true`:
46
+ ``` cpp
47
+ to<C>(r | views::transform([](auto&& elem) {
48
+ return to<range_value_t<C>>(std::forward<decltype(elem)>(elem));
49
+ }), std::forward<Args>(args)...);
50
+ ```
51
+ - Otherwise, the program is ill-formed.
52
+
53
+ ``` cpp
54
+ template<template<class...> class C, input_range R, class... Args>
55
+ constexpr auto to(R&& r, Args&&... args);
56
+ ```
57
+
58
+ Let *input-iterator* be an exposition-only type:
59
+
60
+ ``` cpp
61
+ struct input-iterator { // exposition only
62
+ using iterator_category = input_iterator_tag;
63
+ using value_type = range_value_t<R>;
64
+ using difference_type = ptrdiff_t;
65
+ using pointer = add_pointer_t<range_reference_t<R>>;
66
+ using reference = range_reference_t<R>;
67
+ reference operator*() const;
68
+ pointer operator->() const;
69
+ input-iterator& operator++();
70
+ input-iterator operator++(int);
71
+ bool operator==(const input-iterator&) const;
72
+ };
73
+ ```
74
+
75
+ [*Note 1*: *input-iterator* meets the syntactic requirements of
76
+ *Cpp17InputIterator*. — *end note*]
77
+
78
+ Let *`DEDUCE_EXPR`* be defined as follows:
79
+
80
+ - `C(declval<R>(), declval<Args>()...)` if that is a valid expression,
81
+ - otherwise, `C(from_range, declval<R>(), declval<Args>()...)` if that
82
+ is a valid expression,
83
+ - otherwise,
84
+ ``` cpp
85
+ C(declval<input-iterator>(), declval<input-iterator>(), declval<Args>()...)
86
+ ```
87
+
88
+ if that is a valid expression,
89
+ - otherwise, the program is ill-formed.
90
+
91
+ *Returns:*
92
+ `to<decltype(`*`DEDUCE_EXPR`*`)>(std::forward<R>(r), std::forward<Args>(args)...)`.
93
+