Question: Here is a code snippet illustrating my question:

```
const float D    = 0.1F;
const float A[4] = {sin(0*D), sin(1*D), sin(2*D), sin(3*D)};

```

Imagine that global array `A` is much longer and you don't want to do all of this repetitive typing. Is there a shorter way to initialize array A at compile or initialization time, i.e. without having to write initialization function and call it somewhere in my program?

Answer: 
You could initialize A during dynamic initialization time as follows:

```
const float *init_a(float x_)
{
  static float data[4];
  for(unsigned i=0; i<4; ++i)
    data[i]=sin(i*x_);
  return data;
}

const float D=0.1f;
const float *A=init_a(D);

```
> 
> Imagine that global array A is much longer and you don't want to do all of this repetitive typing. Is there a shorter way to initialize array A at compile or initialization time
> 
> 
> 

Create a generator and pass it through `std::generate_n()` (or plain `std::generate()`).

```
#include <algorithm>
#include <array>
#include <cmath>

template <typename Value_t>
struct SinGenerator{
    SinGenerator(std::size_t start = 0, Value_t counter_scalar = 1)
        : index{start},
          scalar{counter_scalar} {
    }

    Value_t operator()() {
        return sin(index++ * scalar);
    }

    std::size_t index;
    Value_t scalar;
};

template <typename Value_t, std::size_t Size>
std::array<Value_t, Size> init_table(const std::size_t start, 
                                     const Value_t counter_scalar) {
    std::array<Value_t, Size> arr;
    SinGenerator<Value_t> gen(start, counter_scalar);
    std::generate(arr.begin(), arr.end(), gen);
    return arr;
}

const auto kSinTable(init_table<float, 10>(0, 0.1f));

```