between and among: worth Phobosization?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Dec 17 14:22:18 PST 2013


On Tue, Dec 17, 2013 at 01:57:53PM -0800, Andrei Alexandrescu wrote:
> On 12/17/13 1:29 PM, Chris Cain wrote:
> >It doesn't necessarily have to be called "between" but some sort of
> >object (being able to contain the state is important) could contain
> >the concept of a range of values ("inclusive lowerbound", "exclusive
> >upperbound", support things like "opIn" or an opCall to test a value
> >for membership).
> 
> Interval arithmetic
> (http://en.wikipedia.org/wiki/Interval_arithmetic) comes to mind.
> Like bounds-checked numbers, units, and probabilities, it's one of
> those bread-and-butter types that nobody got around to implement for
> Phobos yet.
> 
> In an interval arithmetic approach numbers would compare actually
> equal, i.e. 10 == IntervalInt(5, 100) would be true.
[...]

Ah! "Interval" is the word I was looking for. :)

Ideally, Intervals should implement opApply, 'in', .find, .count, etc.,
and perhaps even interval intersection (but not union since that's not
closed).

I don't like the idea of "IntervalInt"; the base type should be a
template parameter:

	struct Interval(T) { ... }

In my previous post I considered allowing non-homogenous upper/lower
bound types, but in interest of keeping things less messy, it may be
better to just allow only a single type (then you wouldn't need kooky
static-if's around things like opApply, etc.).

Intervals with discrete base types can probably implement the range APIs
for maximum usability with std.algorithm, etc..


T

-- 
Let's eat some disquits while we format the biskettes.


More information about the Digitalmars-d mailing list