<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69675>69675</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`<algorithm>`: `value_type` should use direct-initialization in rangified algo
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hewillk
</td>
</tr>
</table>
<pre>
When a temporary `value_type` needs to be constructed, libc++ sometimes uses copy initialization through `value_type tmp = *first;` or `value_type tmp = ranges::iter_move(first);`
However, this is not exposed in the standard concept, both `indirectly_movable_storable` and `indirectly_copyable_storable` are composed by `constructible_from` instead of `convertible_to`, which indicates that this kind of initialization may not be valid.
I think we should consistently use direct-initialization to construct `value_type`s, i.e. `value_type tmp(*first);` or `value_type tmp( ranges::iter_move(first));`.
However, _Cpp17InputIterator_ ([[iterator.cpp17]](https://eel.is/c++draft/iterator.cpp17#tab:inputiterator)) seems to guarantee the validity of copy initialization. Not sure if this is a LWG.
[testcase](https://godbolt.org/z/6Mn5v7drh) (Content warning: Pedantic).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVNGOqzYQ_RrnZbQITALhgYck27QrtVXf7mNk8ADTNTayh6S5X1-ZZPeqyV5VihQEZzznzDljFQL1FrEWm73YvK7UzIPz9YAXMuZ91Th9rb8NaEEB4zg5r_wVRJGelZnxxNcJRZGCRdQB2EGD0Dob2M8toxbyAIaaVsi9kHsIbkSmEQPMAQO0broCWWJShr4rJmeBB-_mfvhvB-BxApG_gpC7jnxgke9jV-d_gvPK9hhEvhP5jhj9aXRnFHJ7K5bVrV6kryLd_eYueEYfqfJAASiAdQz4z-QCaqDICSGwslp5HdW1OHGEN44XomQ1eWzZXGMf1Rg8BXY-PkSWyuoHVBT-DPNxdOOta7PM-HOSFMGdd2MEkg2MSoPr7pgz-huCXVQlD3AZqB0gdmwVYwAeFN_UvZNdKh_GPqrrorpBOCtDOrnN5i0W2Xe4IITBzWaRHygwWjbX6CLcRL082uh-xOApLSFSpASTZ_eE3H56_GHTlzYLuf1_lz9OSJ6cPh2mKSvf7DTzG6NX7PwJYvO4BHu6v0raiBKb1_iT24F5WtrJo5BHRJNQEPJ4T7f2qmMhjw_FMmfVRIKx18e3GzkIiOOyNf2svLKMuGRtcYD4Gn36YkcS-NMxhNkjUPeZWQW_f_v1LlRs9oyBWxXwK-a9040znDjfC3n8LuSx-MNuzqX2Q2Ql5PbgbLQYLspbsr3Id_AXamWZWiGrZKXrXFd5pVZYZ0VVlmWWrrPVUFc6z5qmLMuiytdYdo0u201XrdOqLTcRQrVMZZ6lMk3zdJ1mSdmV2wLXar3JsiLrSrFOcVRkEmPOY2S4ohBmrIuqKDcroxo0YbmqpLR4geWjkDLeXL6ONS_N3AexTg0FDj9OYWKDdVyP_KBM7zzxMIr8l-XN7vlCu8f95wknu-SPOkIN8cTV7E39MGjiYW6S1o1CHiOV-9_L5N3f2C5piQJiihaB_wYAAP__x2jYhw">