For the purpose of unit testing classes with std::tuple
constructors, I'd like to generate a sample of special cases plus random values for the constructor arguments. Say that I have a std::tuple
of std::vector<T1>
through std::vector<Tn>
, (where each of the Ti
are different) how can I convert this into a std::vector
of the full Cartesian product of all std::tuple<T1, ..., Tn>
combinations?
Specifically, I'd like to have a variadic function template that looks something like this:
template<typename... Args>
std::vector<std::tuple<Args...> cartesian_product(std::vector<Args>...)
{
// template magic or fat mulitple loops?
}
and can be used like this:
// some type to be tested
class MyType
{
MyType(std::tuple<int, bool, std::string>);
// bla
};
// test values for each constructor argument
std::tuple< std::vector<int>, std::vector<bool>, std::vector<std::string> > input {
{ 1, 2, 3}, { false, true}, { "Hello", "World"}
};
// should become 3 x 2 x 2 = 12 cases { {1, false, "Hello"}, ... , {3, true, "World"} }
std::vector< std::tuple<int, bool, std::string> > test_cases = cartesian_product( input );
// can write flat single loop over all cases
for (auto t: test_cases) {
BOOST_CHECK(MyType(t).my_test());
}
Are there any (Boost) libraries that can do this out-of-the-box? How involved is writing variadic templates for this?