1
#include <iostream>
#include <tuple>
#include <type_traits>
template<typename TupleType, typename T, std::size_t index = 0> constexpr std::size_t find_from(){
if constexpr (index == std::tuple_size_v<TupleType>) return index;
if constexpr (std::is_same_v<std::tuple_element_t<index, TupleType>, T>) return index;
return find_from<TupleType, T, index+1>();
}
int main(){
std::cout << find_from<std::tuple<int,double>, int, 0>()<< std::endl;
}
我想在std :: tuple中找到一個類型的索引,爲什麼這個代碼不能在mingw64-gcc中編譯?它似乎告訴我模板遞歸太深。什麼是在std :: tuple中查找類型索引的正確方法? gcc版本7.2.0,編譯-std = C++ 17C++模板遞歸檢查std :: tuple中的類型
@ Jarod42:謝謝,改變了草率的解釋 –
得到了它,我誤解了如果編譯時間 –