On 20/12/2024 04:13, Yu Sheng Oh via Gcc-help wrote:
Cool, thanks. The original code was using `std::array` as the function parameter, but when I changed it to `std::string_view`, it broke the compilation. Both `size()` functions are non-static members, which makes me think that if the context is a constant expression, then static_assert should apply. To conclude, if an object is not constant-evaluated syntactically in a local context (in this case as a function parameter), the compiler still will look at the constexpr member function definition to determine if it could be consteval in a constant expression context, am i correct? Cheers.
A key difference is that with std::array<>, s.size() is a constant expression regardless of whether or not /s/ is a constant expression. The size of a std::array<> is part of its type, which is always a constant expression, while the size of a string view is a run-time value and can only be a constant expression if the string view itself is a constant expression.
David