Skip to content
Snippets Groups Projects
Commit 2d5a024f authored by Michaël El Kharroubi's avatar Michaël El Kharroubi :satellite:
Browse files

[WIP] Add examples for future C++

parent 6ecd9e3a
No related branches found
No related tags found
No related merge requests found
PDFs/*.pdf PDFs/*.pdf
**/Examples/artefacts
\ No newline at end of file
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment