import std;
template foo(alias pred = "a*b"){
void foo(int x, int y){
writeln(x.unaryFun!pred);
}
}
void main(){
foo(5, 4);
}
"a" works, but "b" not work.
I get this error: Error: undefined identifier b
Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 13, 2021 How use Predicate (alias pred = "a*b")? | ||||
---|---|---|---|---|
| ||||
import std; template foo(alias pred = "a*b"){ void main(){ "a" works, but "b" not work. |
May 13, 2021 Re: How use Predicate (alias pred = "a*b")? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcone | On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote: >template foo(alias pred = "a*b"){ First, you really shouldn't use these at all. instead of a string, just pass an actual function to the thing as the predicate. but if you must use it, unaryFun has one argument, so just a. if you want a and b, two arguments, that's binaryFun. |
May 13, 2021 Re: How use Predicate (alias pred = "a*b")? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thursday, 13 May 2021 at 21:38:25 UTC, Adam D. Ruppe wrote: >On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote: >template foo(alias pred = "a*b"){ First, you really shouldn't use these at all. instead of a string, just pass an actual function to the thing as the predicate. but if you must use it, unaryFun has one argument, so just a. if you want a and b, two arguments, that's binaryFun. This is just a simple example of how it works. I won't use it. However, I believe it will be very useful for meta programming. |
May 13, 2021 Re: How use Predicate (alias pred = "a*b")? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thursday, 13 May 2021 at 21:38:25 UTC, Adam D. Ruppe wrote: >On Thursday, 13 May 2021 at 21:30:43 UTC, Marcone wrote: >template foo(alias pred = "a*b"){ First, you really shouldn't use these at all. instead of a string, just pass an actual function to the thing as the predicate. but if you must use it, unaryFun has one argument, so just a. if you want a and b, two arguments, that's binaryFun. Thank you. binaryFun solved the problem. |