Skip to content

Instantly share code, notes, and snippets.

@JoeyAndres
Created December 28, 2016 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeyAndres/c7e0ebc05ecbad5799c94b6d95532980 to your computer and use it in GitHub Desktop.
Save JoeyAndres/c7e0ebc05ecbad5799c94b6d95532980 to your computer and use it in GitHub Desktop.
C++ code for concatenating array.
#include <array> // std::array
#include <algorithm> // std::copy
using std::array;
/**
* Concatenates array.
*
* @tparam T Type of data stored in array.
* @tparam D1 Dimension of first array.
* @tparam D2 Dimension of second array.
*
* @param a1 First array with dimension D1.
* @param a2 Second array with dimension D2.
* @return Concatenated a1 and a2, with dimension D1 + D2.
*/
template <class T, size_t D1, size_t D2>
array<T, D1 + D2> concatArray(const array<T, D1>& a1, const array<T, D2>& a2) {
array<T, D1 + D2> rv;
std::copy(a1.begin(),
a1.end(),
rv.begin());
std::copy(a2.begin(),
a2.end(),
rv.begin() + a1.size());
return rv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment