I am reading some c++ code, and the code list below makes me really confused.
I can guess it tries to define a specialized template, which tries to trait the input args types. But I got a few question:
the first template looks like both deriving and template specialization, if it is deriving, how can a struct derived from itself? if it is a template specialization, where is the template defination?
template<typename F>
struct function_traits : public function_traits<decltype(&F::operator())>
{};
template<typename R, typename C, typename ... Args>
struct function_traits<R(C::*)(Args...) const> {
template<size_t i>
struct arg
{
using type = typename std::tuple_element<i, std::tuple<Args...>>::type;
};
};
The first declaration is just a definition of the primary template for struct function_traits
. Note that there's no problem with a particular specialisation of a template being derived from a different specialisation of that template (as long as there are no loops). Remember that each specialisation of a class template is a distinct, unrelated type.
The second declaration simply introduces a partial specialisation for function types, whose instantiations will likely get used as the base-class for the primary template (since the primary template derives from a specialisation whose template argument is a member function type).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With