So we have the
explicit specifier for constructors, would it be better if we could have
explicit for any type of callable functions as well. At the moment we can use a template function where the template parameters are set to a specific type:
1 2 3 4
|
template <typename T = double>
T f(T) {
// ...
}
|
I would also like to avoid using RTTI for this purpose.
So I think it would be better to have the syntatic sugar, this usage meaning that all the parameters have to be explicit:
1 2 3
|
explicit void f(double input) {
// ...
}
|
Going further, we could have the explicit being optional for some of the function parameters:
1 2 3
|
void f(explicit double input, float other) {
// ...
}
|
While we are at it, I propose to have a way of turning off implicit type conversion, maybe with a
#pragma and/or a compiler option? The
#pragma would be for Translation Unit level control, while the compiler option would be global. Implicit type conversions are the source of many errors according to Jason Turner.
Any thoughts?