The elements in the array are not default constructible therefore we need to initialize the array directly from elements in std::vector.
#include <array>
#include <vector>
class foo {
public:
foo(int i, float j) : i{i}, j{j} {}
private:
int i;
float j;
};
void bar() {
std::vector<foo> baz = {{0, 1}, {0, 2}, {0, 3}};
constexpr size_t copyCount = 2;
std::array<foo, copyCount> copiedElements =
/* somehow initilize this to the copyCount elements from baz */;
}
An elegant and simple solution would be preferred.