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

Add headers for future example

parent 2d5a024f
Branches
Tags
No related merge requests found
#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 <array>
#include <iostream>
#include <ranges>
#include <vector>
// Experimental CPP features
#include "includes/cartesian_product.hpp"
#include "includes/mdspan.hpp"
constexpr int dim_x = 5;
constexpr int dim_y = 5;
int main() {
std::array<float, dim_x * dim_y> data{0};
auto xs = std::views::iota(0, dim_x);
auto ys = std::views::iota(0, dim_y);
auto idxs = std::views::cartesian_product(xs, ys);
auto md = std::experimental::mdspan{data.data(), dim_x, dim_y};
std::for_each(idxs.begin(), idxs.end(), [&md](auto tup) {
const auto& [x, y] = tup;
std::cout << x << "," << y << std::endl;
});
std::cout << "\n";
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
.PHONY:clean all
INCLUDES_WARNINGS:=--diag_suppress useless_using_declaration
all: artefacts/future
artefacts/future: artefacts/future.o
nvc++ $^ -o $@
artefacts/%.o: %.cpp
nvc++ --std=c++23 $(INCLUDES_WARNINGS) -c $^ -o $@
clean:
rm -vf artefacts/**
\ 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