operator overloading outside the type
Kapendev
alexandroskapretsos at gmail.com
Sat Oct 25 12:52:34 UTC 2025
On Saturday, 25 October 2025 at 09:41:33 UTC, David O wrote:
> On Wednesday, 2 April 2025 at 12:19:44 UTC, Dukc wrote:
>
> I have a generic struct
>
> struct BaseUnits(string type)
> {
> ...
> }
>
> I can define lengths:
>
> enum m = BaseUnits!"m"(1.0);
> enum km = BaseUnits!"m"(1.0E3);
>
> and areas:
>
> enum m2 = BaseUnits!"m2"(1.0);
> enum km2 = BaseUnits!"m2"(1.0E6);
>
> I can scale them and add them:
>
> auto a = 7*m;
> auto a = m + km;
>
> Now I want to make a volume:
>
> BaseUnits!"m3" b = m * m2;
>
> But I need a free standing operator overload for this!
Old forum post :)
In this case, I'm not sure. All of them are the same type, no? So
you could probably write some template hell and get something out
of it. I'm not monkeyyyyy sadly, so can't really help that much.
More information about the Digitalmars-d
mailing list