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 <iostream> | |
// --- | |
#include <array> | |
#include <utility> | |
template <typename T> | |
using c_array = T[]; | |
template<typename T, size_t N, size_t... Indices> | |
constexpr auto make_array(T (&&src)[N], std::index_sequence<Indices...>) { | |
return std::array<T, N>{{ std::move(src[Indices])... }}; | |
} | |
template<typename T, size_t N> | |
constexpr auto make_array(T (&&src)[N]) { | |
return make_array(std::move(src), std::make_index_sequence<N>{}); | |
} | |
// --- | |
struct Point { int x, y; }; | |
std::ostream& operator<< (std::ostream& os, const Point& p) { | |
return os << "(" << p.x << "," << p.y << ")"; | |
} | |
int main() { | |
auto xs = make_array(c_array<Point>{{1,2}, {3,4}, {5,6}, {7,8}}); | |
for (auto&& x : xs) { | |
std::cout << x << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment