I have this piece of code:
template <typename T>
struct Base {
constexpr std::uint8_t getValue() noexcept {
return static_cast<T*>(this)->getValueImpl();
}
};
class Derived : public Base<Derived> {
friend struct Base<Derived>;
constexpr std::uint8_t getValueImpl() noexcept {
return sizeof(std::uint8_t);
}
};
template <typename ...Args>
void doStuff(Args &&...args) {
constexpr auto alrightVariable = sizeof...(args);
constexpr auto errorVariable = (args.getValue() + ...);
}
int main() {
doStuff(Derived());
return 0;
}
And it throw compile error: "function parameter 'args' with unknown value cannot be used in a constant expression"
Where I was wrong? All variables can be calculated at compile time...