Seems the compiler ignores the constexpr qualifier when it is added to a non-constexpr function. Why is that?
The following code compiles fine and runs.
#include <iostream>
#include <string>
using std::string; using std::cout; using std::endl;
constexpr bool is_shorter(const string &lft, const string &rht) // this is not a constexpr function
{
return lft.size() < rht.size();
}
int main()
{
bool restul = is_shorter("Hello", "World!");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire