digitalmars.D.learn - UFCS not working with alias
- Andre Pany (14/14) Sep 07 2016 Hi,
- rikki cattermole (3/4) Sep 07 2016 No.
- Andre Pany (23/28) Sep 07 2016 I simplified my example too much. Yes in the example above I can
- rikki cattermole (4/29) Sep 07 2016 People have tried, this is the behavior as designed.
- Andre Pany (5/11) Sep 07 2016 Thanks, this answer my question.
- Steven Schveighoffer (17/42) Sep 08 2016 There is a workaround, identified by Vladimir Panteleev
- Andre Pany (15/31) Sep 08 2016 Thanks for this insight. In my case I prepare a presentation
Hi, I just noticed ufcs does not work with alias. Is this limitation needed? void foo(int a) {} void main() { alias bar = foo; 3.foo(); 3.bar(); } Last line fails with "no property 'bar' for type int. Should I open an enhancement request? Kind regards André
Sep 07 2016
On 07/09/2016 8:06 PM, Andre Pany wrote:Should I open an enhancement request?No. It works outside of the function (part of lookup rules).
Sep 07 2016
On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote:On 07/09/2016 8:06 PM, Andre Pany wrote:I simplified my example too much. Yes in the example above I can move the alias outside the main function. Here is a more complex example. As I use the input parameter args in the alias, I cannot move the alias outside the main function. import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.keyPredicateFilter; } Is there a workaround? Or is still a valid scenario to change the lookup rules? Kind regards AndréShould I open an enhancement request?No. It works outside of the function (part of lookup rules).
Sep 07 2016
On 07/09/2016 8:26 PM, Andre Pany wrote:On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote:People have tried, this is the behavior as designed. The workaround is simple, don't use UFCS. I won't repeat the explanation or reasoning here, plenty of posts on it ;)On 07/09/2016 8:06 PM, Andre Pany wrote:I simplified my example too much. Yes in the example above I can move the alias outside the main function. Here is a more complex example. As I use the input parameter args in the alias, I cannot move the alias outside the main function. import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.keyPredicateFilter; } Is there a workaround? Or is still a valid scenario to change the lookup rules?Should I open an enhancement request?No. It works outside of the function (part of lookup rules).
Sep 07 2016
On Wednesday, 7 September 2016 at 08:35:26 UTC, rikki cattermole wrote:On 07/09/2016 8:26 PM, Andre Pany wrote:Thanks, this answer my question. Kind regards André[...]People have tried, this is the behavior as designed. The workaround is simple, don't use UFCS. I won't repeat the explanation or reasoning here, plenty of posts on it ;)
Sep 07 2016
On 9/7/16 4:26 AM, Andre Pany wrote:On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote:There is a workaround, identified by Vladimir Panteleev (https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/): import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} alias I(alias x) = x; void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.I!keyPredicateFilter; } Unfortunately, you can't alias the I!someSymbol, as that has the same problem. -SteveOn 07/09/2016 8:06 PM, Andre Pany wrote:I simplified my example too much. Yes in the example above I can move the alias outside the main function. Here is a more complex example. As I use the input parameter args in the alias, I cannot move the alias outside the main function. import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.keyPredicateFilter; } Is there a workaround? Or is still a valid scenario to change the lookup rules?Should I open an enhancement request?No. It works outside of the function (part of lookup rules).
Sep 08 2016
On Thursday, 8 September 2016 at 13:38:54 UTC, Steven Schveighoffer wrote:There is a workaround, identified by Vladimir Panteleev (https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/): import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} alias I(alias x) = x; void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.I!keyPredicateFilter; } Unfortunately, you can't alias the I!someSymbol, as that has the same problem. -SteveThanks for this insight. In my case I prepare a presentation about D (audience doesn't now anything about D) and tried to make my D code as beautiful as possible. As solution I created now a free template method and hide it in a library module. T[] filterByKeyPredicate(T)(T[] arr, string[string] keyPredicate) { ...filter!.... } This way I can use UFCS. Kind regards André
Sep 08 2016