Created
January 20, 2017 02:02
-
-
Save merryhime/b9b9c7fd3338cf6c9729f861936a3bbc to your computer and use it in GitHub Desktop.
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> | |
#include <functional> | |
template <typename T, size_t N, size_t M, size_t... iota_N, size_t... iota_M> | |
auto append_impl( | |
std::index_sequence<iota_N...>, | |
std::index_sequence<iota_M...>, | |
const std::array<T, N>& a, | |
const std::array<T, M>& b | |
) -> std::array<T, N+M> { | |
return { a[iota_N]..., b[iota_M]... }; | |
} | |
template <typename T, size_t N, size_t M> | |
auto append(const std::array<T, N>& a, const std::array<T, M>& b) -> std::array<T, N+M> { | |
return append_impl(std::make_index_sequence<N>{}, std::make_index_sequence<M>{}, a, b); | |
} | |
#include <cstdlib> | |
#include <cstdio> | |
int main(int argc, char** argv) { | |
std::array<int, 1> a {1}; | |
std::array<int, 2> b {2, 3}; | |
auto c = append(a, b); | |
for (auto v : c) { | |
printf("%i\n", v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment