strangeqargo strangeqargo - 6 months ago 47
C++ Question

Unable to understand this Template parameter

Maybe it's flu, or I'm just plain stupid, but I can't understand a part of this Crow framework code. My inner C++ parser fails.

template <typename MW>
struct check_before_handle_arity_3_const
{
template <typename T,
//this line
void (T::*)(int, typename MW::context&) const = &T::before_handle
>
struct get
{ };
};


I know it's a template parameter inside template declaration. It looks like maybe some lambda or function pointer type parameter... but, I'm not sure.
Can someone explain this line?

Answer

void (T::*)(int, typename MW::context&) const is a non-type template parameter. It is a pointer to a member function of T.

With the use of = &T::before_handle, its default value is set to &T::before_handle.