Quick A: When you want to use the variable in a way that requires its value to be known at compile time.
Here's a short nugget that helps demonstrate the meaning of constexpr
:
Why is constexpr required even though member function is constexpr?
The following does not compile unless I put
constexpr
beforeinitializer_list
:constexpr std::initializer_list<int> il = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::array<int, il.size()> a;But
initializer_list size
isconstexpr
:constexpr size_type size() const;
Add a Comment
Comments are closed.