On Thu, Nov 29, 2018 at 3:38 PM Gavin Lambert via Boost < boost@lists.boost.org> wrote:
On 30/11/2018 06:12, Hans Dembinski wrote:
This is not a good match here, because -1 here does not have the
meaning of "value is missing", but it really is the logical index for the virtual bin that spans from -infinity to the lower edge of the first bin in the axis.
Value arrow: -inf ——————— | ——————— | —————— | —————— |—————————> +inf bin -1 bin 0 bin 1 bin 2 bin 3
I think representing the underflow bin with -1 and the overflow bin
with the value returned by size() is very intuitive and elegant.
Conventionally your size_type should be the same type returned by size() and used for indexing. So I would expect that type to be int, given the above.
Having said that, you're already departing from standard container conventions by having size() return a number that is *sometimes* 2 smaller than the "real" number of bins, which might frustrate generic algorithms.
Completely without tongue in cheek, I wonder if it might be better to not provide a size() method at all (to avoid container implications which you do not satisfy) and spell it as bin_count() or something distinct instead.
+1 If the operation differs semantically from .size() in standard containers, then it shouldn't be called size().