#include<tuple>
#include<type_traits>
#include<string>
#include<iostream>
template<int Index, class Search, class First, class... Types>
struct get_internal
{
typedef typename get_internal<Index + 1, Search, Types...>::type type;
static constexpr int index = Index;
};
template<int Index, class Search, class... Types>
struct get_internal<Index, Search, Search, Types...>
{
typedef get_internal type;
static constexpr int index = Index;
};
template<class T, class... Types>
T get(std::tuple<Types...> tuple)
{
return std::get<get_internal<0,T,Types...>::type::index>(tuple);
}
int main()
{
std::tuple<int, double, std::string> test{1, 1.7, "test"};
std::cout<<"get<0> == get<int> :"<< (std::get<0>(test) == get<int>(test))<< "\n";
std::cout<<"get<1> == get<double> :"<<(std::get<1>(test) == get<double>(test))<< "\n";
std::cout<<"get<2> == get<std::string> :"<<(std::get<2>(test) == get<std::string>(test))<< "\n";
}
I2luY2x1ZGU8dHVwbGU+CiNpbmNsdWRlPHR5cGVfdHJhaXRzPgojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGlvc3RyZWFtPgoKdGVtcGxhdGU8aW50IEluZGV4LCBjbGFzcyBTZWFyY2gsIGNsYXNzIEZpcnN0LCBjbGFzcy4uLiBUeXBlcz4Kc3RydWN0IGdldF9pbnRlcm5hbAp7Cgl0eXBlZGVmIHR5cGVuYW1lIGdldF9pbnRlcm5hbDxJbmRleCArIDEsIFNlYXJjaCwgVHlwZXMuLi4+Ojp0eXBlIHR5cGU7CiAgICAgICAgc3RhdGljIGNvbnN0ZXhwciBpbnQgaW5kZXggPSBJbmRleDsKfTsKCnRlbXBsYXRlPGludCBJbmRleCwgY2xhc3MgU2VhcmNoLCBjbGFzcy4uLiBUeXBlcz4Kc3RydWN0IGdldF9pbnRlcm5hbDxJbmRleCwgU2VhcmNoLCBTZWFyY2gsIFR5cGVzLi4uPgp7Cgl0eXBlZGVmIGdldF9pbnRlcm5hbCB0eXBlOwoJc3RhdGljIGNvbnN0ZXhwciBpbnQgaW5kZXggPSBJbmRleDsKfTsKCnRlbXBsYXRlPGNsYXNzIFQsIGNsYXNzLi4uI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