Skip to content

Instantly share code, notes, and snippets.

@Zikoel
Created August 23, 2017 16:11
Show Gist options
  • Save Zikoel/599b2962311f9562bd1206e9de9e65c5 to your computer and use it in GitHub Desktop.
Save Zikoel/599b2962311f9562bd1206e9de9e65c5 to your computer and use it in GitHub Desktop.
A way for retrieve type from complex object inside a tuple.
#include <iostream>
#include <tuple>
#include <unordered_map>
template<typename ...TKeyTypes>
struct A {
std::tuple<std::unordered_map<TKeyTypes, size_t>...> tupled_maps;
};
int main()
{
A<int, double> a;
using mapType = std::tuple_element<0, decltype(a.tupled_maps)>::type;
using mapKeyType = mapType::key_type;
static_assert(std::is_same<mapType, std::unordered_map<int, size_t>>::value, "!");
static_assert(std::is_same<mapKeyType, int>::value, "!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment