Create a constexpr function. - C++ Data Type

C++ examples for Data Type:constexpr

Description

Create a constexpr function.

Demo Code

#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;
}

Result


Related Tutorials