From 10ee9a9c7c0742f808b4e732579dc3578cb5c2b5 Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
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')

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)
-- 
cgit v1.2.3