constexpr functions can be evaluated at compile time. They are not required.
For the code you provided, the compiler does not really do this, and bin receives a call at runtime; this means that the function cannot be thrown out of the assembly. Explicitly requiring the values ββto be constexpr with
constexpr auto i = bin(5), j = bin(27);
bin calls are made at compile time, as shown here . Via
cout << bin(5) << '\n' << bin(27) << '\n';
corresponding emitted code
movl $5, %edi
When the call is canceled, the size is the same for both versions.
source share