[Feature Request] Keywords for symbol operators

Danilo codedan at aol.com
Mon Feb 26 10:57:00 UTC 2024


On Monday, 26 February 2024 at 10:40:27 UTC, user1234 wrote:
> Small advice for this particular case: you should specify the 
> type of the lambda parameters, so that `and`, `or`, and `not` 
> dont become templates. That way errors will occur earlier, for 
> example if something that's not evaluable to bool is passed by 
> error.

In this case you would need to use cast(bool) like this:
```d
auto and(T,U)(T value1, U value2) => (cast(bool)value1) && 
(cast(bool)value2);
```
because int does not automatically cast to bool.

Using Steve‘s code, for example:

```d
bool and(bool a, bool b) => a && b;

void main() {
    int foo, bar = 1;

    if(foo.and(bar)) { }
}
```


Anyway, the original request was not about UFCS functions.
The codes are just something to play with, playing with ideas. 
Nothing useful. ;)


More information about the Digitalmars-d mailing list