Am I evil for this?

Paul Backus snarwin at gmail.com
Mon Oct 24 14:16:57 UTC 2022


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"));
}

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

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


More information about the Digitalmars-d mailing list