I want to implement this function (a function which can concatenate any number of arrays, and it considers the value category as well):
template <typename ELEMENT, std::size_t ...SIZE>
constexpr auto concat(std::array<ELEMENT, SIZE> &&&...arrays) {
return std::array<ELEMENT, SUMMED_SIZE>{ CONCATENATED_ARRAY_ELEMENTS };
}
Notes:
- By
&&&, I mean that each array inarrayscan be rvalue/lvalue ref (can be mixed) - By
SUMMED_SIZE, I mean the the sum of SIZE (this is trivial) - By
CONCATENATED_ARRAY_ELEMENTS, I mean all the elements of each array ofarraysconcatenated. If an array inarraysis an rvalue/lvalue, then the corresponding elements inCONCATENATED_ARRAY_ELEMENTSshould also be rvalues/lvalues. - I don't want to have extra move/copy ctor calls (otherwise it would be trivial to implement this by using recursion), I want to have only one move/copy for each element in
arrays. ELEMENTmay not be default-constructible, so elements must be constructed by copy/move ctor.
Is this possible to do?
It is not hard to implement this function for two arrays (godbolt), but I'm not sure how to generalize this to more than two arrays. I could write 3/4/5/etc-argument function manually, but the number of needed functions grows exponentially.