On Wed, Dec 03, 2014 at 01:20:59AM +0200, ketmar via Digitalmars-d wrote:
> On Tue, 2 Dec 2014 14:00:09 -0800
> "H. S. Teoh via Digitalmars-d" <[email protected]> wrote:
> 
> >     // mymod.d
> >     module mymod;
> >     struct S {
> >             // Now everyone is happy, right...?
> >             import std.range : isInputRange;
> > 
> >             void method(R)(R range)
> >                     if (isInputRange!R)
> >             {
> >             }
> >     }
> ah, how i HAET that! importing std.traits in module scope just to have
> preconditions in templates drives me mad. i want to be able to insert
> import statements before that `if`! and i want that imports to not
> affect template body too.
[...]

Technically, you *can* do that, but it's a lot more verbose (plus, ddoc
doesn't know how to generate docs for eponymous templates properly and
it looks ugly):

        template method(R)
        {
                import std.range : isInputRange;

                void method(R range)
                        if (isInputRange!R)
                { ... }
        }

Certainly defeats the convenient shorthand of eponymous templates. :-(


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius

Reply via email to