Constraints
Chris Cain
clcain at uncg.edu
Wed May 9 08:58:28 PDT 2012
We can already kind of do what you're asking without a language
feature. For instance, if you want to define that something is a
type of range...
struct MyRange { ... }
static assert(isInputRange!MyRange); // won't compile unless
MyRange is an input range
On Wednesday, 9 May 2012 at 15:04:51 UTC, İbrahim Gökhan
YANIKLAR wrote:
> // implement foo's without constraints
> //------------------------------------------------------------
>
> void foo(Range)(Range r)
> if (isInputRange!Range && !isForwardRange!Range)
> { }
>
> void foo(Range)(Range r)
> if (isForwardRange!Range && !isBidirectionalRange!Range &&
> !isRandomAccessRange!Range)
> { }
>
> void foo(Range)(Range r)
> if (isBidirectionalRange!Range && !isRandomAccessRange!Range)
> { }
>
> void foo(Range)(Range r)
> if (isRandomAccessRange!Range)
> { }
And these could certainly use some library sugar. How about this:
template isJustInputRange(R) {
enum bool isJustInputRange = isInputRange!R &&
!isForwardRange!R;
}
template isJustForwardRange(R) ...etc...
More information about the Digitalmars-d
mailing list