Lets say I have:
(please ignore the fact that I am using strncmp
in C++)
if (!strncmp(some_str, "constant", strlen("constant"))) {}
The strlen
can be evaluated at compile time but it can't be eliminated because the function is not constexpr
.
One way around would be (accepted only by g++
):
constexpr size_t len = strlen("constant");
if (!strncmp(some_str, "constant", len)) {}
but this is harder to read and less practical.
Is there any way to specify constexpr
for a part of a statement?