how to define my own traits

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 27 09:28:13 PDT 2017


On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote:
> I've looked into Phobos to emulate it when defining my own 
> trait template, and when I see this:
>
> module std.range.primitives;
> // ...
> 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
>     }));
>
> I wonder, why that unused parameter (inout int = 0)?
> In my project () { /* ... */ } works the same for a custom 
> trait.

Even Andrei was baffled:

http://forum.dlang.org/thread/nepm2k$311l$1@digitalmars.com


More information about the Digitalmars-d-learn mailing list