Skip to content

Instantly share code, notes, and snippets.

@Kakadu
Created September 19, 2013 11:12
Show Gist options
  • Save Kakadu/6621985 to your computer and use it in GitHub Desktop.
Save Kakadu/6621985 to your computer and use it in GitHub Desktop.
C++ dependent types array concat
//g++ -std=c++11 a.cpp
#include <array>
template <typename T, size_t a, size_t b>
std::array<T, a + b> concat(std::array<T, a> const& x, std::array<T, b> const& y) {
std::array<T, a + b> z;
std::copy(x.begin(), x.end(), z.begin());
std::copy(y.begin(), y.end(), z.begin() + x.size());
return z;
}
#include <cstdio>
int main() {
for (auto const& x : concat(std::array<int, 3>{{1, 2, 3}},
std::array<int, 2>{{4, 5}}))
printf("%d\n", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment