In C++14 and beyond, constexpr for member functions no longer implies const.
struct Value
{
int i = 5;
constexpr bool not_five() // requires const to compile
{
return this->i != 5;
}
};
int main()
{
constexpr Value v{6};
static_assert(v.not_five());
}
error: passing ‘const Value’ as ‘this’ argument discards qualifiers [-fpermissive]
static_assert(v.not_five());
^
It seems as though calling a non-const constexpr member function at compile time implies the mutation of a constant, since the object it's called against exists at compile time and is being mutated. Under what circumstances is the concept of a non-const constexpr member function useful?