diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-29 00:04:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-29 00:04:36 +0000 |
commit | 10ee9a9c7c0742f808b4e732579dc3578cb5c2b5 (patch) | |
tree | 977cb31f824890b4c817bbf1e18bb98563583502 /lib | |
parent | constexpr collections helpers (diff) | |
download | ilt-10ee9a9c7c0742f808b4e732579dc3578cb5c2b5.tar.bz2 ilt-10ee9a9c7c0742f808b4e732579dc3578cb5c2b5.tar.xz ilt-10ee9a9c7c0742f808b4e732579dc3578cb5c2b5.zip |
Add helper to produce cartesian product of two arrays
Diffstat (limited to 'lib')
-rw-r--r-- | lib/collections.hpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/collections.hpp b/lib/collections.hpp index c9b0127..beb01f8 100644 --- a/lib/collections.hpp +++ b/lib/collections.hpp @@ -13,6 +13,20 @@ operator+(const std::array<T, first> & a, const std::array<T, second> & b) return r; } +template<typename T, typename V, std::size_t first, std::size_t second> +constexpr std::array<std::pair<T, V>, first * second> +operator*(const std::array<T, first> & a, const std::array<V, second> & b) +{ + std::array<std::pair<T, V>, first * second> r; + auto out = r.begin(); + for (const auto & ae : a) { + for (const auto & be : b) { + *out++ = {ae, be}; + } + } + return r; +} + template<typename T, std::size_t N> constexpr auto operator*(const std::array<T, N> & in, auto && f) |