Named template constraints

Tim Holzschuh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 22 07:07:39 PDT 2014


Hi there,

I recently read the 'More Templates' chapter of Ali's book (<-- thanks 
for that ;) ).
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();
     }() ) );
}

But at Phobos I always see definitions like this (std.range : isInputRange):

template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140422/fc1963e7/attachment.html>


More information about the Digitalmars-d-learn mailing list