From 2d5a024f627202436148455f4c230b3665ece739 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=20Kharroubi=20Micha=C3=ABl?=
 <michael.el-kharroubi@hesge.ch>
Date: Mon, 12 Feb 2024 17:26:34 +0100
Subject: [PATCH] [WIP] Add examples for future C++

---
 .gitignore                  |  3 ++-
 Examples/cartesian_prod.cpp | 23 +++++++++++++++++++++++
 Examples/mdspan.cpp         | 23 +++++++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 Examples/cartesian_prod.cpp
 create mode 100644 Examples/mdspan.cpp

diff --git a/.gitignore b/.gitignore
index a91c6d0..c5cf88a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-PDFs/*.pdf
\ No newline at end of file
+PDFs/*.pdf
+**/Examples/artefacts
\ No newline at end of file
diff --git a/Examples/cartesian_prod.cpp b/Examples/cartesian_prod.cpp
new file mode 100644
index 0000000..df4ea74
--- /dev/null
+++ b/Examples/cartesian_prod.cpp
@@ -0,0 +1,23 @@
+#include <array>
+#include <iostream>
+#include <list>
+#include <ranges/v3/view/cartesian_product.hpp>
+#include <ranges>
+#include <string>
+#include <vector>
+
+namespace stdexp = std::experimental;
+
+void print(std::tuple<char const&, int const&, std::string const&> t, int pos) {
+    const auto& [a, b, c] = t;
+    std::cout << '(' << a << ' ' << b << ' ' << c << ')' << (pos % 4 ? " " : "\n");
+}
+
+int main() {
+    const auto x = std::array{'A', 'B'};
+    const auto y = std::vector{1, 2, 3};
+    const auto z = std::list<std::string>{"α", "β", "γ", "δ"};
+
+    for (int i{1}; auto const& tuple : stdexp::views::cartesian_product(x, y, z))
+        print(tuple, i++);
+}
\ No newline at end of file
diff --git a/Examples/mdspan.cpp b/Examples/mdspan.cpp
new file mode 100644
index 0000000..d594e99
--- /dev/null
+++ b/Examples/mdspan.cpp
@@ -0,0 +1,23 @@
+#include <experimental/mdspan>
+#include <iostream>
+namespace stdex = std::experimental;
+int main() {
+    std::array d{
+        0,
+        5,
+        1,
+        3,
+        8,
+        4,
+        2,
+        7,
+        6,
+    };
+
+    stdex::mdspan m{d.data(), stdex::extents{3, 3}};
+    static_assert(m.rank() == 2, "Rank is two");
+    for (std::size_t i = 0; i < m.extent(0); ++i)
+        for (std::size_t j = 0; j < m.extent(1); ++j)
+            std::cout << "m(" << i << ", " << j << ") == " << m(i, j) << "\n";
+    return 0;
+}
\ No newline at end of file
-- 
GitLab