4 ms·
> The issue here is a quirk of overloading rules: after template instantiations two overloads of __fill_a are available, one with a deduced 'int' type for the f
by BeeOnRope 7y ago
> The issue here is a quirk of overloading rules: after template instantiations two overloads of __fill_a are available, one with a deduced 'int' type for the fill value type and another with a 'char' type. Both are perfectly valid instantiations, but the 'int' valued one is preferred by the partial ordering rules as it does not require a conversion.
Eh right, that's something I somewhat misunderstood. I just thought the memset overload didn't match at all because the pointer and value-to-fill types are different, but of course it would match, with a conversion: but the other overload wins as you point out.
> I think this might easily be solved by making the type of the value to be filled in a separate template parameter even for the pointer variant.
Yeah, although you'd need a couple variants of that still with different enable_if conditions to filter the safe cases for this optimization ("complex" value-to-fill types can't use this, for some unclear definition of "complex").
> Also, in addition to pointers, the memset optimization should really be applied for all contiguous iterators (for example std::vector::iterator).
This already works, see fill3 at [1].
I didn't check, but assumed decaying certain iterators to pointers was the function of the `std::__niter_base(iter)` calls in std::fill.
---
[1] https://godbolt.org/z/Eqcsx7 https://godbolt.org/z/Eqcsx7