D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12421 - Allow simpler syntax for lambda template declarations
Summary: Allow simpler syntax for lambda template declarations
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: pull
: 7308 9426 (view as issue list)
Depends on:
Blocks:
 
Reported: 2014-03-20 03:23 UTC by Andrej Mitrovic
Modified: 2016-01-03 14:20 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2014-03-20 03:23:28 UTC
-----
void main()
{
    import std.algorithm;
    import std.traits;

    {
        static auto notEmpty(Arr)(Arr arr) { return !arr.filter!(a => a > 0.0).empty; }
        assert(notEmpty([0.0, 0.0, 0.1]));
    }

    {
        // simpler syntax should be supported
        alias notEmpty = a => a.filter!(b => b > 0.0).empty;
        assert(notEmpty([0.0, 0.0, 0.1]));
    }
}
-----

Note how much code has to be written for a "throwaway" inline function definition in the first case. This could be simplified by supporting the second syntax.
Comment 1 Andrej Mitrovic 2014-03-20 03:24:24 UTC
A slightly more fair comparison if we take into account that 'static' acts as 'auto':

-----
void main()
{
    import std.algorithm;
    import std.traits;

    {
        static notEmpty(A)(A a) { return !a.filter!(b => b > 0.0).empty; }
        assert(notEmpty([0.0, 0.0, 0.1]));
    }

    {
        // simpler syntax should be supported
        alias notEmpty = a => a.filter!(b => b > 0.0).empty;
        assert(notEmpty([0.0, 0.0, 0.1]));
    }
}
-----
Comment 3 Kenji Hara 2014-06-07 12:00:59 UTC
Spec change:
https://github.com/D-Programming-Language/dlang.org/pull/589
Comment 4 Kenji Hara 2014-06-09 04:56:32 UTC
*** Issue 7308 has been marked as a duplicate of this issue. ***
Comment 5 Martin Nowak 2014-07-04 22:59:28 UTC
*** Issue 9426 has been marked as a duplicate of this issue. ***
Comment 6 Vladimir Panteleev 2015-06-26 12:29:03 UTC
Workaround:

alias I(alias X) = X;
alias notEmpty = I!(a => a.filter!(b => b > 0.0).empty);

http://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/
Comment 7 github-bugzilla 2015-10-13 12:36:02 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/445e1734f450f8e4a5c2f38b5ad0dfe2c937f897
fix Issue 12421 - Allow simpler syntax for lambda template declarations

https://github.com/D-Programming-Language/dmd/commit/78820390932309c1c5503770ebcaec338bd69b88
Merge pull request #3638 from 9rnsr/fix12421

Issue 12421 - Allow simpler syntax for lambda template declarations
Comment 8 github-bugzilla 2015-11-01 12:07:21 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/dc8edfebf6bf9b48bcf33b2e79c0ed305ec2fde0
fix Issue 12421 - Allow simpler syntax for lambda template declarations

https://github.com/D-Programming-Language/dlang.org/commit/72ed432292028ff55caef307c5abee5cb97eb199
Merge pull request #1147 from 9rnsr/fix12421

Issue 12421 - Allow simpler syntax for lambda template declarations
Comment 9 github-bugzilla 2015-11-02 00:46:25 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/9446e513e4ba1b984d03b159ad0820c1e58024d5
fix Issue 12421 - Allow simpler syntax for lambda template declarations

https://github.com/D-Programming-Language/dlang.org/commit/5d2f9dfd8a496896e22bf227855b6de9629b3f71
Merge pull request #1148 from MartinNowak/alias_funclit

fix Issue 12421 - Allow simpler syntax for lambda template declarations
Comment 11 github-bugzilla 2016-01-03 14:01:49 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/445e1734f450f8e4a5c2f38b5ad0dfe2c937f897
fix Issue 12421 - Allow simpler syntax for lambda template declarations

https://github.com/D-Programming-Language/dmd/commit/78820390932309c1c5503770ebcaec338bd69b88
Merge pull request #3638 from 9rnsr/fix12421
Comment 12 github-bugzilla 2016-01-03 14:20:07 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dlang.org

https://github.com/D-Programming-Language/dlang.org/commit/9446e513e4ba1b984d03b159ad0820c1e58024d5
fix Issue 12421 - Allow simpler syntax for lambda template declarations

https://github.com/D-Programming-Language/dlang.org/commit/5d2f9dfd8a496896e22bf227855b6de9629b3f71
Merge pull request #1148 from MartinNowak/alias_funclit