Please excuse me for my poor English.
There is a big difference between the correct C ++ construct:
struct Length { double l; operator =!?:%+-*/...(); }; struct Mass { double l; operator =!?:%+-*/...(); };
and proposed extension
struct Length : public double ; struct Mass : public double ;
And that difference is the behavior of the this . this is a pointer and using a pointer gives you little chance of using registers for calculations, because registers have no address in regular processors. It is worse, using a pointer, to make the compiler suspicious that two pointers may indicate the same memory.
This will put extreme strain on the compiler to optimize trivial operations.
Another problem is the number of errors: reproducing exactly the entire behavior of statements is an absolute error (in order to make the constructor explicit, it does not prohibit all cases of implicits). The probability of error when building such an object is quite high. This is not equivalent to being able to do something through hard work or to do it already done.
Compiler developers will introduce type checking code (maybe some errors, but the accuracy of the compiler is much better than client code, due to some error in the compiler they generate countless errors), but the main behavior of the operation will remain unchanged, as well as a few errors than usually.
The proposed alternative solution (using structures during the debugging phase and real floats during optimization) is interesting, but has its drawbacks: it increases the likelihood of errors only in the optimized version. An optimized debugging application is expensive.
You can implement a good suggestion for an initial @Rocketmagnet request for integer types using:
enum class MyIntA : long {}; auto operator=!?:%+-*/...(MyIntA); MyIntA operator "" _A(long);
The error level will be quite high, for example, using a one-member trick, but the compiler will treat thoses types in the same way as built-in integers (including registration and optimization), thanks for inlining.
But this trick cannot be used (unfortunately) for floating point numbers, and the most pleasant need is, obviously, checking for valid sizes. Do not mix apples and pears: adding length and area is a common mistake.
Calling Straustrap by @Jerry doesn't matter. Virtuality makes sense mainly for public inheritance, and the need here is for private inheritance. Considering the “chaotic” C conversion rules (does C ++ 14 have something non-chaotic?) The basic type is also not useful: the goal is to not have default conversion rules, and not follow the standard ones.