I
Ioannis Vranos
Proposal:
We can increase type safety in C++ by adding a single keyword. The current proposal uses the keyword "only".
Example 1:
only int x= 4;
x= 5; // Ok
x= 5.0; // Error
x= 5U // Error
Example 2:
int i= 5;
only unsigned x= 4U;
x= 5; // Error
x= 5LU; // Error
x= i; // Error
Example 3:
only float f= 4.0F;
f= 4; // Error
f= 5.0; // Error
f= 4.0F; // OK
// It accepts any built in type
void somefunc(const int &x);
// It accepts only an int and a const int object
void somefunc(only const int &x);
It is simple like that, and the concept is backwards compatible.
What do you think?
We can increase type safety in C++ by adding a single keyword. The current proposal uses the keyword "only".
Example 1:
only int x= 4;
x= 5; // Ok
x= 5.0; // Error
x= 5U // Error
Example 2:
int i= 5;
only unsigned x= 4U;
x= 5; // Error
x= 5LU; // Error
x= i; // Error
Example 3:
only float f= 4.0F;
f= 4; // Error
f= 5.0; // Error
f= 4.0F; // OK
// It accepts any built in type
void somefunc(const int &x);
// It accepts only an int and a const int object
void somefunc(only const int &x);
It is simple like that, and the concept is backwards compatible.
What do you think?