D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6484 - compose can't take multi arg functions
Summary: compose can't take multi arg functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2011-08-12 13:17 UTC by Ellery Newcomer
Modified: 2020-10-29 02:34 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 Ellery Newcomer 2011-08-12 13:17:24 UTC
unless only passed one function.

Of course, this doesn't make sense for any but the innermost function, e.g.

int f(int){..} 
int g(int){..}
int h(int,int,int){...}

alias compose!(f,g,h) F;
assert(F(x,y,z) == f(g(h(x,y,z))));

This functionality can be trivially added by changing in composeImpl

doIt(E)(E a)

to 

doIt(E...)(E a)

If conserving param modifiers is desired, it would likely take a good deal more work.
Comment 1 github-bugzilla 2012-08-27 01:34:27 UTC
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/aa40b3b47d64dbf55bd559f113148925ced61ccf
Merge pull request #753 from mylodon/enh6484

fix issue 6484
Comment 2 Andrej Mitrovic 2013-02-05 13:19:21 UTC
(In reply to comment #1)
> Commit pushed to master at https://github.com/D-Programming-Language/phobos
> 
> https://github.com/D-Programming-Language/phobos/commit/aa40b3b47d64dbf55bd559f113148925ced61ccf
> Merge pull request #753 from mylodon/enh6484
> 
> fix issue 6484

Note: this pull is unrelated to this bug.
Comment 3 Justin Whear 2014-06-06 18:40:32 UTC
Kenji's made some recent changes to compose and I cannot reproduce in 2.065.

int f(int a){ return a; } 
int g(int a){ return a; }
int h(int a,int b,int c){ return a * b * c; }

import std.functional;
alias compose!(f,g,h) F;
static assert(F(1,2,3) == f(g(h(1,2,3))));
Comment 4 Paul Backus 2020-10-28 16:20:43 UTC
This bug still exists in 2.094.0. The example in comment 3 fails to compile, with the following output:

---
bug.d(7): Error: template `std.functional.compose!(f, compose).compose` cannot deduce function from argument types `!()(int, int, int)`, candidates are:
/usr/include/dmd/phobos/std/functional.d(1161):        `compose(E)(E a)`
bug.d(7):        while evaluating: `static assert(compose(E)(E a)(1, 2, 3) == f(g(h(1, 2, 3))))`
---
Comment 5 Dlang Bot 2020-10-29 01:55:14 UTC
@pbackus created dlang/phobos pull request #7685 "Fix issue 6484 - compose can't take multi arg functions" fixing this issue:

- Fix issue 6484 - compose can't take multi arg functions

https://github.com/dlang/phobos/pull/7685
Comment 6 Dlang Bot 2020-10-29 02:34:52 UTC
dlang/phobos pull request #7685 "Fix issue 6484 - compose can't take multi arg functions" was merged into master:

- 4083852b4b3637595d1a35eb85fc97b7dcc6ced0 by Paul Backus:
  Fix issue 6484 - compose can't take multi arg functions

https://github.com/dlang/phobos/pull/7685