Idiom for initializing an std::array using a generator function taking the index?
Suppose I have a function T foo(size_t i). What would be an elegant and succinct way of constructing an object arr, of type std::array, so that we have arr[i] == foo(i)?
If possible, I would like for this construction to work even when T is not a default-initializable type.
Notes:
- Since
Tis not default-initializable, the code can't start withstd::arrayand then some initialization.arr; - The code must work for any value of
N, generically.