C++ examples for Data Type:constexpr
Create a constexpr function.
#include <array> #include <cstdint> #include <iostream> constexpr int ArraySizeFunction(int parameter) { return parameter; } int main()// w w w. ja va2s.c om { constexpr int ARRAY_SIZE{ ArraySizeFunction(5) }; std::array<int, ARRAY_SIZE> myArray{ 1, 2, 3, 4, 5 }; for (auto&& number : myArray) { std::cout << number << std::endl; } return 0; }