Próbuję znaleźć typ A
w opakowaniu parametrów:znaleźć w opakowaniu typu parametru
template <int I, typename A, typename B, typename ...C>
struct index_of
{
static constexpr int const value =
std::is_same<A, B>::value ? I : index_of<I + 1, A, C...>::value;
};
template <int I, typename A, typename B>
struct index_of<I, A, B>
{
static constexpr int const value =
std::is_same<A, B>::value ? I : -1;
};
To wydaje się działać, ale nie jestem w stanie wyeliminować parametr nietypowe I
, które chciałbym być parametrem domyślnym, ale nie może tego zrobić, z powodu pakietu parametrów na końcu. Jak wyeliminować/ukryć I
, aby metafunkcja stała się bardziej przyjazna dla użytkownika?
Ale druga i trzecia metafunkcja nie obsługuje poprawnie duplikatów. – user1095108
@ user1095108 Masz rację, uprościłem to. Naprawiony. – dyp