0

I have a 2-dimensional vector of enums std::vector<std::vector<enum>>, the enum can have the values a (0), b (1), c(2). I would like to randomly set one of the a's to c and thought I'll try out the ranges library.

Currently I have a view of all the as in my 2d vector using this:

auto g = view::join(vec) | filter([](my_enum x){ return x == my_enum::a; };

I found view::sample that sounds useful to randomly select an element, but didn't know how to use it since I got confused about the size of another range it needs as a parameter? (view::sample doc)

Next step would also be to mutate that randomly selected element. As far as I understood it, ranges::v3::view only provides a non-mutable view on elements. So is it at all possible to mutate a selected element?

DenverCoder21
  • 879
  • 3
  • 16
  • 34

0 Answers0