Disallow non natural implicit conversions
As discussed with @labourasse, some C++
-like implicit conversions can be confusing for the user.
For instance, one can wonder what is produced by the following code
N n = 1.9;
Z z = -1.3;
What are actually the values contained by n
and z
?
Up to now, we purposely followed C++
rules, so that one will get n=1
and z=-1
.
It is true that these implicit conversions are not completely obvious and that their mathematical meaning is at least questionable.
Thus, @labourasse suggested (convincingly) that these should not be allowed.
Obviously since N
and Z
are subsets of R
,*
R x = 1;
N n = 3;
x = n;
will remain a valid: these are not conversions (which have no mathematical meaning)!
Also, forbidding implicit conversions will be more consistent with future types. For instance, one will not be able to convert implicitly R^n
elements to R
, or complex values to real values.
However, I still believe that the use of natural integers N
should be used along with relative integers Z
. Thus we will keep "conversions" such as
N n = 3-1;
3-1
is interpreted as a relative integer (belonging to Z
) but is also 2
which is a natural integer. One may decide later to remove N
, if we do not get any benefits from it and if its confusing. C++/20
should provide dealing with invalid integers (such as NaN for floating point values), and it might be the answer. One could also add a checking mode for natural integers.
Same kind of consideration could be discussed for Boolean set B
. Should we continue to allow implicit conversions of elements of R
, Z
and N
to B
? By now
R x = 1.3;
if (x) { // if x!=0, it casts to true, following C++ rules
// do something
}
is allowed. Should it be?