Having a tuple of types, I want to generate the tuple containing all the possible pairs. I'm having trouble understanding why the pairs with the last types in the first position (like: {B,_}) appear multiple times.
#include <iostream>
#include <type_traits>
#include <tuple>
#include <utility>
struct A; struct B; struct C; struct D; struct E; struct F;
using Types = std::tuple<A,B>;
template <typename TupleAll, typename Tuple1, typename Tuple2>
struct PairsGenerator {
using Type = std::tuple<>;
};
template <typename TupleAll, typename T, typename U, typename... Ts, typename... Us>
struct PairsGenerator<TupleAll, std::tuple<T, Ts...>, std::tuple<U, Us...>> {
using Type = decltype(std::tuple_cat(
std::declval<std::tuple<std::pair<T, U>>>(),
std::declval<typename PairsGenerator<TupleAll, std::tuple<T, Ts...>, std::tuple<Us...>>::Type>(),
std::declval<typename PairsGenerator<TupleAll, std::tuple<Ts...>, TupleAll>::Type>()));
};
template <typename TypesTuple>
using Pairs = typename PairsGenerator<TypesTuple, TypesTuple, TypesTuple>::Type;
int main() {
//std::cout << typeid(decltype(std::declval<Pairs<Types>>())).name() << std::endl;
std::cout << std::boolalpha << std::is_same_v<std::tuple<
std::pair<A,A>,
std::pair<A,B>,
std::pair<B,A>,
std::pair<B,B>,
std::pair<B,A>,
std::pair<B,B>
>, Pairs<Types>>;
}
Returns true, instead it should be, but the following is false
std::cout << std::boolalpha << std::is_same_v<std::tuple<
std::pair<A,A>,
std::pair<A,B>,
std::pair<B,A>,
std::pair<B,B>
>, Pairs<Types>>;