Question Details

No question body available.

Tags

c++ lambda c++17 constexpr

Answers (1)

Accepted Answer Available
Accepted Answer
October 19, 2025 Score: 21 Rep: 183,805 Quality: Expert Completeness: 50%

While the variable is not a constant and not usable itself in a constant expression, members of the variable can be constant expressions. In this case the operator() of the lambda object is marked as constexpr, and it doesn't depend on the lambda object, so it can be used even though the object isn't.

We can get a little more of a simplified example with

int main()
{
    std::array nums{1, 3, 5, 7};

static_assert(nums.size() == 4); }

Here nums is not a constant, but size() always is as it's marked constexpr, and it just returns N, so it is still usable.