[PATCH] Optimize seed_seq construction
Antony Polukhin
antoshkka@gmail.com
Tue Aug 17 13:40:37 GMT 2021
вт, 17 авг. 2021 г. в 16:37, Jonathan Wakely <jwakely@redhat.com>:
<...>
> Thanks, this is a nice improvement. We can avoid tag dispatching to
> make it simpler though:
>
> @@ -3248,6 +3249,9 @@ namespace __detail
> template<typename _InputIterator>
> seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
> {
> + if _GLIBCXX17_CONSTEXPR
> (__is_random_access_iter<_InputIterator>::value)
> + _M_v.reserve(std::distance(__begin, __end));
> +
> for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
> _M_v.push_back(__detail::__mod<result_type,
> __detail::_Shift<result_type, 32>::__value>(*__iter));
>
> The call to std::distance is well-formed for input iterators, but we
> won't actually call it unless we have random access iterators.
>
> Unless you see a problem with this that I'm missing, I'll go with that version.
Looks much better. Thanks!
--
Best regards,
Antony Polukhin
More information about the Libstdc++
mailing list