diff --git a/.gitignore b/.gitignore index a91c6d052cd9fe479cd9947b5df9a85a03941831..c5cf88a88e0ae3ee15be3ed80f1689a909ffe9b5 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 0000000000000000000000000000000000000000..df4ea746104d66910f0a08f9916dfaf93ffa5f95 --- /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 0000000000000000000000000000000000000000..d594e9931dd283797b28454c4e154dd491f3ee8c --- /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