Created
September 19, 2013 11:12
-
-
Save Kakadu/6621985 to your computer and use it in GitHub Desktop.
C++ dependent types array concat
This file contains hidden or 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
| //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