jeudi 16 juin 2016

C++ Making tuple from two tuples by randomly choosing their elements

I had a really hard time coming up with the title so it's hardly saying anything, sorry.

WHAT I WANT EXACTLY: I have a pair of tuples with unknown types and unknown number of arguments, but types of these two tuples and variable count is exactly the same, e.g.:

std::pair<std::tuple<Ts...>, std::tuple<Ts...>>

Let's call those tuples A and B

Now i want to make a new tuple from those two with the exactly same types and argument count (std::tuple<Ts...>) in the following way:

1. Randomly choose tuple A or B for an element (I guess I can do it by calling std::experimental::rand_int(0,1) or another generator).

2. Place this element in new tuple (let's call it C) (maybe std::experimental::apply could be of any help to point 2. and 3.?)

3. Repeat steps 1-2 until the end of tuple A and B

EXAMPLE:

A = std::tuple<double, int, long, int> {2.7, 1, 22, 4};
B = std::tuple<double, int, long, int> {12.4, 7, -19, 18};

After algorithm I want to receive, for example:

C = std::tuple<double, int, long, int> {12.4, 1, 22, 18}; 

(or any other combination of A and B following this scheme)




Aucun commentaire:

Enregistrer un commentaire