samedi 2 novembre 2019

Is there any use for constexpr references?

As the title says, is there any useful case for constexpr references? Like so:

static const int myvar = myfunc();  // myfunc is not constexpr
constexpr const int& myref = myvar;

myref can't be used where a constant expression is expected anyway, because the variable it refers to is not a constant expression. I don't see how this is different from:

static const int myvar = myfunc();
const int& myref = myvar;

The generated assemblies appears to be also the same.

Aucun commentaire:

Enregistrer un commentaire