C++ examples for Data Type:constexpr
C++14 constexpr function can limit the maximum size of an array.
#include <array> #include <cstdint> #include <iostream> constexpr int ArraySizeFunction(int parameter) { return parameter *2; } int main()// w w w.j av a 2 s . c om { constexpr int ARRAY_SIZE{ ArraySizeFunction(15) }; std::array<int, ARRAY_SIZE> myArray{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for (auto&& number : myArray) { std::cout << number << std::endl; } return 0; }