B
Bo Persson
Kai-Uwe Bux said:It should not. Such comparison is handled gracefully by promotion
rules. I
think, the code is required to compile.
It does with a warning, but the result is incorrect. :-(
If Size is ptrdiff_t for example, and n is negative, comparing to a
size_t doesn't work.
We are on the right track though, and I think this one could work:
template < typename OutIter, typename Size, typename T >
void fill_n ( OutIter first, Size n, const T & value ) {
if (0 < n) // n must be positive
{
for ( std::size_t count = n; 0 < count; --count ) {
*first = value;
++first;
}
}
}
If we sort out the possibly negative n first, the remaining values
must be convertible to size_t (assuming size_t is the largest unsigned
type
Bo Persson