в настоящее время у меня есть отдельно следующим образом: < /p>
Код: Выделить всё
template
concept iterator_1 = requires(T const& t) {
t.function1();
};
< /code>
template
static float getterFunction(R const& r)
{
return r.function1();
}
< /code>
template
concept iterator_2 = requires(T const& t) {
t.function2();
};
< /code>
template
static float getterFunction(R const& r)
{
return r.function2();
}
< /code>
Я хочу использовать общую getterfunction, чтобы выбрать function1 (), function2 (), ... и т.д. с условием if, например, следующим образом: < /p>
template
float getterFunction(A const& a)
{
auto i = -1;
if (something==0) {
i = a.function1();
}
else if (something==1) {
i = a.function2();
}
else if {
...
}
return i;
}
< /code>
Я хотел бы использовать эту общую getterfunction следующим образом: < /p>
template
void DoSomething(typename B::iterator const& b)
{
float value = getterFunction(b);
...
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... e-template
Мобильная версия