Why doesn't `opAssign` work for my templated struct?
kdevel
kdevel at vogtner.de
Sat Nov 9 15:09:38 UTC 2024
On Friday, 8 November 2024 at 21:55:53 UTC, Liam McGillivray
wrote:
> I am working on a library for making types representing units
> of measurement. Base units [...]
> ```
> [...]
> enum Milligrams : BaseUnit!Milligrams;
> enum Millimoles : BaseUnit!Millimoles;
> [...]
> ```
Shouldn't (base) units be named in singular form?
> ```
> [...]
> Milligrams mass = Milligrams(20f);
> [...]
> ```
I would have expected something like
```
Mass!milligram mass = Mass!milligram(20);
```
The variable mass represents a quantity measured in baseunits
(milligrams). It does not represent the base unit. I'm afraid
that your design will allow the assignment of amounts of
substance to variables of "type" Milligrams.
More information about the Digitalmars-d-learn
mailing list