For integers, we really can do something similar in one line with:
enum class qty_t : int64_t {};
That's a good positive example. Sadly not so sanguine for double or complex.
While we are technically out of luck for other types, a wrapping aggregate struct isn’t that horrible (though potentially with an attribute that hints it wants the abi of the wrapped field).
I'm not so skilled. I find it a wee bit horrible especially w.r.t. constructors.
Still, cloning, and possibly cloning with extensions, seems a useful thing. Perhaps too useful though ;-)
For aggregates you don’t need to write constructors. For double/other non-integrals it would be as simple as
struct radians{
double value;
};
Also, I suppose a question would be how you intended to get the value out of the “new” types. If by static_cast, I could see the removal of the boilerplate to get that being a potential positive for your method (though maybe not enough to justify a core language extension, I don’t know).
I also don’t see why the 2nd example can’t just use inheritance. I would suppose you would lose standard layout if you wanted to add any fields using normal inheritance (would this be a problem with cloning).
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals