How to Create constexpr Array Where Elements Depend on the Array’s Size?

32 views Asked by At

How can I create a constexpr array, where the array elements are calculated and depend on the size of the array? Look at the example below in the initializer list to see what I mean.

template <short NUM_TRIANGLES>
constexpr auto circle() {
    constexpr float angle = (M_PI / 2.0f) / NUM_TRIANGLES;
    constexpr std::array<float, NUM_TRIANGLES> angles{angle, 2 * angle, 3 * angle, ... /* LOOK HERE */};

    /// ...
}
0

There are 0 answers