Boost logo

Boost :

Subject: Re: [boost] [histogram] should some_axis::size() return unsigned or int?
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-12-03 00:15:48

On 30/11/2018 20:43, Olaf van der Spek wrote:
> Not really:

Isn’t that proposed definition of ssize() essentially identical to

     // member function
     constexpr difference_type ssize() const
     { return std::distance(begin(), end()); }
     // or moral equivalent, for containers that can implement it
     // more efficiently another way.

     // non-member function in std::
     template <class C>
     constexpr auto ssize(const C& c)
     { return distance(begin(c), end(c)); }
     // or calling member ssize() if it exists

The above seems "better" in that it allows a container intended
exclusively for small sizes to use a difference_type smaller than ptrdiff_t.

(In the text it explains why it's a bad idea for a container using
uint16_t sizes with more than 32767 elements to use int16_t as a
difference_type, but as I understand it that's already undefined
behaviour -- size_type is required to be larger than difference_type and
difference_type should be able to express std::distance(begin(), end())
or some algorithms will break.)

Boost list run by bdawes at, gregod at, cpdaniel at, john at