Just using decltype
with std::declval
(from <type_traits>
) should be fine:
class Return = decltype(std::declval<Derived const>().get(std::declval<Misc>()...))
Вопрос
Consider the following code :
template <class Crtp>
struct Base
{
const float& get(const short int i) const {return std::get<0>(tuple);}
const double& get(const int i) const {return std::get<1>(tuple);}
const long double& get(const unsigned long long int i) const {return std::get<2>(tuple);}
std::tuple<float, double, long double> tuple;
};
struct Derived
: public Base<Derived>
{
template <class... Misc, class Return = /*SOMETHING*/>
const Return& test(Misc&&... misc) const
{return this->get(std::forward<Misc>(misc)...);}
};
This is an EXAMPLE code: it does not illustrate something useful, and the problem could be solved using an auto function declaration for instance. I know that and I do not search a workaround concerning this particular example.
My question is : what would be /*SOMETHING*/
in order to get the return type of the correct overload of get
depending of the passed Misc
types ?
Решение
Just using decltype
with std::declval
(from <type_traits>
) should be fine:
class Return = decltype(std::declval<Derived const>().get(std::declval<Misc>()...))