Named template constraints
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 22 11:04:02 PDT 2014
On 04/22/2014 07:07 AM, Tim Holzschuh via Digitalmars-d-learn wrote:
> read the 'More Templates' chapter of Ali's book (<-- thanks
> for that ;) ).
Yay! :)
> At the section 'Named constraints', there were a definition like this:
>
> template isUsable(T)
> {
> enum isUsable = is ( typeof(
> {
> T obj;
> obj.call();
> obj.otherCall(1);
> obj.ye tAnotherCall();
> }() ) );
> }
That is how Phobos used to be.
> But at Phobos I always see definitions like this (std.range :
> isInputRange):
>
> template isInputRange(R)
> {
> enum bool isInputRange = is(typeof(
> (inout int = 0)
I had noticed that as well and am curious myself. My guess is that it is
a syntax issue where that default parameter list makes it a stronger
delegate syntax. :p
> {
> R r = R.init; // can define a range object
> if (r.empty) {} // can test for empty
> r.popFront(); // can invoke popFront()
> auto h = r.front; // can get the front of the range
> }));
> } What does (inout int = 0) mean/affect here? I created the same
> template for myself just without the (inout int = 0) and it worked (at
> least with a dummy struct).. - Tim
Same here: I cannot find an example where the first version does not
work. (?)
Ali
More information about the Digitalmars-d-learn
mailing list