Re: between and among: worth Phobosization? (reprise)

2015-03-27 Thread John Colvin via Digitalmars-d
On Friday, 27 March 2015 at 01:53:22 UTC, H. S. Teoh wrote: On Fri, Mar 27, 2015 at 01:37:45AM +, Vladimir Panteleev via Digitalmars-d wrote: On Thursday, 26 March 2015 at 22:23:12 UTC, Andrei Alexandrescu wrote: >New idea: > >bool ordered(pred = "a < b")(T...)(T values) So... isSorted for

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Fri, Mar 27, 2015 at 01:37:45AM +, Vladimir Panteleev via Digitalmars-d wrote: > On Thursday, 26 March 2015 at 22:23:12 UTC, Andrei Alexandrescu wrote: > >New idea: > > > >bool ordered(pred = "a < b")(T...)(T values) > > So... isSorted for tuples? That's pretty much what it is, and I'm wo

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 26 March 2015 at 22:23:12 UTC, Andrei Alexandrescu wrote: New idea: bool ordered(pred = "a < b")(T...)(T values) So... isSorted for tuples?

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d
On 3/26/15 4:03 PM, H. S. Teoh via Digitalmars-d wrote: On Thu, Mar 26, 2015 at 03:48:26PM -0700, Andrei Alexandrescu via Digitalmars-d wrote: On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote: Don't like the name, though. Prefer 'isOrdered', otherwise it sounds like some kind of sorting

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 03:48:26PM -0700, Andrei Alexandrescu via Digitalmars-d wrote: > On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote: > >Don't like the name, though. Prefer 'isOrdered', otherwise it sounds > >like some kind of sorting algorithm (as in, returns an ordered > >sequence of

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d
On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote: Don't like the name, though. Prefer 'isOrdered', otherwise it sounds like some kind of sorting algorithm (as in, returns an ordered sequence of its arguments). Must be single-word name or nothing per Andrei's Hierarchy Of Naming Abstracti

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Jakob Ovrum via Digitalmars-d
On Thursday, 26 March 2015 at 22:30:54 UTC, H. S. Teoh wrote: As for combinations of < and <=, what about taking multiple template arguments? E.g.: if (isOrdered!("<", "<=")(0, x, 10)) { ... } In that case, wouldn't it be more readable to just do: if (0 < x <= 10) { ... } ?

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 03:23:12PM -0700, Andrei Alexandrescu via Digitalmars-d wrote: > On 3/26/15 2:52 PM, Vladimir Panteleev wrote: > >On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev > >wrote: > >>Oh yeah, this assumes hi <= lo. I thought this was part of the > >>function contrac

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d
On 3/26/15 2:52 PM, Vladimir Panteleev wrote: On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev wrote: Oh yeah, this assumes hi <= lo. I thought this was part of the function contract. I meant lo <= hi New idea: bool ordered(pred = "a < b")(T...)(T values) { foreach (i, _;

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 26 March 2015 at 21:09:16 UTC, Andrei Alexandrescu wrote: On 3/26/15 11:41 AM, Vladimir Panteleev wrote: I don't know if it's been mentioned yet, but there exists an optimization for between with integer arguments: bool between(T, U1, U2)(T v, U1 lo, U2 hi) if (is(T:long) && is

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev wrote: Oh yeah, this assumes hi <= lo. I thought this was part of the function contract. I meant lo <= hi

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d
On 3/26/15 11:41 AM, Vladimir Panteleev wrote: On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote: On 12/16/13 12:38 PM, Andrei Alexandrescu wrote: bool between(T, U1, U2)(T v, U1 lo, U2 hi) { return v >= lo && v <= hi; } Add? Looks like among() has proven its worth sinc

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d
On 3/26/15 11:41 AM, Vladimir Panteleev wrote: On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote: On 12/16/13 12:38 PM, Andrei Alexandrescu wrote: bool between(T, U1, U2)(T v, U1 lo, U2 hi) { return v >= lo && v <= hi; } Add? Looks like among() has proven its worth sinc

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote: On 12/16/13 12:38 PM, Andrei Alexandrescu wrote: bool between(T, U1, U2)(T v, U1 lo, U2 hi) { return v >= lo && v <= hi; } Add? Looks like among() has proven its worth since we introduced it. Now I somehow forgot betwee

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Tobias Pankrath via Digitalmars-d
I think it would be a good addition. Would we want to allow specifying the inclusion like below: auto between(string inclusion = "[]")(int v, int a, int b) { +1

Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Jesse Phillips via Digitalmars-d
On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote: On 12/16/13 12:38 PM, Andrei Alexandrescu wrote: bool between(T, U1, U2)(T v, U1 lo, U2 hi) { return v >= lo && v <= hi; } uint among(T, Us...)(T v, Us vals) { foreach (i, U; Us) { if (v == vals[i]) return

Re: between and among: worth Phobosization? (reprise)

2015-03-14 Thread Andrei Alexandrescu via Digitalmars-d
On 12/16/13 12:38 PM, Andrei Alexandrescu wrote: bool between(T, U1, U2)(T v, U1 lo, U2 hi) { return v >= lo && v <= hi; } uint among(T, Us...)(T v, Us vals) { foreach (i, U; Us) { if (v == vals[i]) return i + 1; } return 0; } Add? Looks like among() has prov