Can someone explain this error?

Bill Baxter wbaxter at gmail.com
Tue Sep 23 17:21:28 PDT 2008


On Wed, Sep 24, 2008 at 9:08 AM, Sean Kelly <sean at invisibleduck.org> wrote:
> == Quote from Bill Baxter (wbaxter at gmail.com)'s article
>> On Wed, Sep 24, 2008 at 8:26 AM, Sean Kelly <sean at invisibleduck.org> wrote:
>> >    class C
>> >    {
>> >        this() {}
>> >        this( int x, int y ) {}
>> >    }
>> >
>> >    void main()
>> >    {
>> >        auto c = alloc!(C);
>> >        auto d = alloc!(C)( 1, 2 );
>> >    }
>> >
>> >    T alloc(T, Params ...)( Params params )
>> >    {
>> >        return new T( params );
>> >    }
>> >
>> > $ dmd test
>> > test.d(10): Error: expected 0 arguments, not 2
>> >
>> This is the thing Walter made work in D2 but not D1.
>>   http://d.puremagic.com/issues/show_bug.cgi?id=493
>
> Hm.  It was D2 that gave me the error.

Odd.  This template is in std.algorithm for instance:

    Ranges[0] filter(alias pred, Ranges...)(Ranges rs) { ... }

and called using

   filter!("a<10")(a);

in the unittests.

Here's the full code:
----------------------------------------------------------------------
Ranges[0] filter(alias pred, Ranges...)(Ranges rs)
{
    alias unaryFun!(pred) fun;
    typeof(return) result;
    // Accumulate
    foreach (i, range; rs[0 .. $]) // all inputs
    {
        foreach (it; begin(range) .. end(range)) // current input
        {
            if (fun(*it)) result ~= *it;
        }
    }
    return result;
}

unittest
{
    int[] a = [ 3, 4 ];
    auto r = filter!("a > 3")(a);
    assert(r == [ 4 ]);

    a = [ 1, 22, 3, 42, 5 ];
    auto under10 = filter!("a < 10")(a);
    assert(under10 == [1, 3, 5]);
}
----------------------------------------------------


More information about the Digitalmars-d-learn mailing list