From 10ee9a9c7c0742f808b4e732579dc3578cb5c2b5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 29 Dec 2022 00:04:36 +0000 Subject: Add helper to produce cartesian product of two arrays --- lib/collections.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/collections.hpp') 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 & a, const std::array & b) return r; } +template +constexpr std::array, first * second> +operator*(const std::array & a, const std::array & b) +{ + std::array, first * second> r; + auto out = r.begin(); + for (const auto & ae : a) { + for (const auto & be : b) { + *out++ = {ae, be}; + } + } + return r; +} + template constexpr auto operator*(const std::array & in, auto && f) -- cgit v1.2.3