Created
December 28, 2016 23:16
-
-
Save JoeyAndres/c7e0ebc05ecbad5799c94b6d95532980 to your computer and use it in GitHub Desktop.
C++ code for concatenating array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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