mercredi 29 juillet 2015

Is constexpr always forced to be evaluated compile-time or only when it is needed? [duplicate]

This question already has an answer here:

What I meant for 'needed' is something like this.

constexpr int f(int a) {
  return a;
}

constexpr int a = f(2); // since a is constexpr, f() should be constexpr

Is is possible that f() is called in runtime if a is not constexpr?

int a = f(2);

Since a is not constexpr, f() doesn't need to be evaluated in compile-time. But I wonder if constexpr is forced to be evaluted in compile-time when all the arguments are compile-time constants.

Aucun commentaire:

Enregistrer un commentaire