Consider the following inlined function :
// Inline specifier version
#include<iostream>
#include<cstdlib>
inline int f(const int x);
inline int f(const int x)
{
return 2*x;
}
int main(int argc, char* argv[])
{
return f(std::atoi(argv[1]));
}
and the constexpr equivalent version :
// Constexpr specifier version
#include<iostream>
#include<cstdlib>
constexpr int f(const int x);
constexpr int f(const int x)
{
return 2*x;
}
int main(int argc, char* argv[])
{
return f(std::atoi(argv[1]));
}
My question is : does the constexpr
specifier imply the inline
specifier in the sense that if a non-constant argument is passed to a constexpr
function, the compiler will try to inline
the function as if the inline
specifier was put in its declaration ?
Does the C++11 standard guarantee that ?