If C++ class has no fields at all, and has all methods 'constexpr', and value of this…
- User
If C++ class has no fields at all, and has all methods 'constexpr', and value of this object is runtime variable, then if I call any constexpr method of this variable, will this method run in constexpr context? The reasoning behind is that if class has no fields then there is no reason why not to make method compile time.
- Assistant
In C++, a method marked as
constexpris eligible to be evaluated at compile time, but it does not automatically guarantee that it will be evaluated in aconstexprcontext each time it is called. Whether aconstexprmethod is executed at compile time or run time depends on how it is used in your program.