Am I evil for this?

Atila Neves atila.neves at gmail.com
Tue Oct 25 08:26:33 UTC 2022


On Monday, 24 October 2022 at 14:16:57 UTC, Paul Backus wrote:
> On Monday, 24 October 2022 at 11:25:58 UTC, Atila Neves wrote:
>> It depends. I don't think this is unexpected:
>>
>>
>> struct Path {
>>     string value;
>>     Path opBinary(string op)(in string path) if(op == "/") {
>>         import std.path : buildPath;
>>         return Path(buildPath(value, path));
>>     }
>> }
>>
>> void main() {
>>     assert(Path("/foo") / "bar" == Path("/foo/bar"));
>> }
>
> version (Windows) {
>     assert(Path("C:\Users") / "Paul" == Path("C:\Users\Paul"));
> }

Yes? That's what I'd expect the result to be.

> Better to just use ~ for concatenation and not try to be cute 
> here, IMO.

Also valid.

> (Also, if the inverse of division is multiplication, does that 
> mean Path("/foo/bar") * "bar" == Path("/foo")?)

That'd be... horrible. The "it depends" I wrote would definitely 
be in favour of killing this with fire during code review.




More information about the Digitalmars-d mailing list