#include <iostream>
#include <tuple>
using namespace std;

template<unsigned TAG_VALUE>
struct tagged_struct {
	constexpr static auto S_TAG = TAG_VALUE;
};

template<typename Tuple, size_t TAG, size_t I = std::tuple_size<Tuple>::value - 1>
struct tag_to_index {
	constexpr static auto value = std::tuple_element<I, Tuple>::type::S_TAG == TAG ? I : tag_to_index<Tuple, TAG, I - 1>::value;
};

template<typename Tuple, size_t TAG>
struct tag_to_index<Tuple, TAG, -1> { constexpr static auto value = -1; };

int main() {
	tuple<tagged_struct<15>, tagged_struct<17>, tagged_struct<29>> structs;
	
	cout << tag_to_index<decltype(structs), 17>::value << endl;
	
	return 0;
}