Here's something semi-connected that only works statically:
#include <array> template <typename T, unsigned int ...I, typename U, unsigned int N> std::array<T, sizeof...(I)> build_array(U const (&src)[N]) { return std::array<T, sizeof...(I)> { { static_cast<T>(src[I])... } }; }
Using:
auto arr = build_array<int, 0, 1, 3, 9>(X);
Example:
#include <iostream> int main() { double X[10] = { 10., 9., 8., 7., 6., 5., 4., 3., 2., 1. }; auto arr = build_array<int, 0, 1, 3, 9>(X); for (auto i : arr) { std::cout << i << std::endl; } }
source share