Currently, I have a variant
of map
types, where I hard-code all variations of key-value pairs, as such:
// for example, if we support std::string and int types as key-value pair
using MapCombinator = std::variant<
std::map<std::string, std::string>,
std::map<std::string, int>,
std::map<int, std::string>,
std::map<int, int>>;
In the real case, I need to support key-value pairs of all fundamental types, in addition to std::string
. This is why, I would like to only specify a tuple of types, something more like this:
using KVTypes = std::tuple<std::string, int, etc...>;
using MapCombinator = MapCombinatorImpl::type;
where MapCombinatorImpl
contains the template-meta-programming logic that creates the final variant type. I would expect something as such:
template<typename... SupportedTypes>
struct MapCombinatorImpl {
typedef ??? type;
};
I don't want to use macros for this, and if it is too complicated to do with template-meta-programming, I'll support only a manageable subset of fundamental types.
Help appreciated for the implementation with template-meta-programming.
std::make_index_sequence<tuple_size<Tuple> * tuple_size<Tuple>>
, thenstd::variant<std::map<std::tuple_element_t<Is / tuple_size<Tuple>, Tuple>, std::tuple_element_t<Is % tuple_size<Tuple>, Tuple>>...>
. – Clannish