Are there reasons not to marking all the functions contexpr implicitly after C++11? I think the principle "Caedite eos! Novit enim Dominus qui sunt eius" would work here, because in case of:
template< typename T >
constexpr
T f(T t) { return t; }
int main(int argc, char *argv[])
{
f(1);
f(argc);
return 0;
}
f(argc) automatically recognized as not constexpr, as opposed to f(1). On the one hand compiler can defenitely infer applicability of constexpr specifier by itself for functions, which can be constexpr generally, on the other hand it can ensure, that functions can never be constexpr if they not matches the rules for constexpr functions.
Also there is a plenty of problems with STL. Say, regarding non-constexpr operator [] of non-const std::array in constant expressions or regarding non-constexpr std::swap, which prevents using of std::swap in constant expressions.
Why there no such language feature as implicit constexpr specifier enabled by default for all the functions (or even for statements, expressions and subexpressions)? Is there performance reasons or something else?
Aucun commentaire:
Enregistrer un commentaire