Everything important said already, you can get the function just a little bit more flexible:
template <typename T, size_t N>
std::array<T, N> copyarray(T const (&input)[N])
{
std::array<T, N> result;
std::copy(std::begin(input), std::end(input), std::begin(result));
return result;
}
(Late) edit: There is a disadvantage with the approach above: You'll need to copy the returned array on assignment, as it doesn't contain any truely movable data (that's the same for raw arrays already). You can avoid this drawback by directly copying into the target array:
template <typename T, size_t N>
void copyarray(std::array<T, N>& target, T const (&source)[N])
{
std::copy(std::begin(source), std::end(source), std::begin(target));
}
This mimicks the assignment target = source
; if you like better, you can swap the parameters, of course, to have the output parameter last.
Usage (as is):
int source[7] = { };
std::array<int, sizeof(source)/sizeof(*source)> target;
copyarray(target, source);