jeudi 3 octobre 2019

how to avoid code duplication with const and non-const member functions being input into templates

when attempting to get functions' signatures when they are input into templates its fairly easy, just do the following:

template <class OutType, class... ArgTypes>
void foo(OutType (*func)(ArgTypes...));

it is only marginally more complicated to get a non-static member function:

template <class OutType, class MemberOf, class... ArgTypes>
void foo(OutType (MemberOf::*func)(ArgTypes...));

// or

template <class OutType, class MemberOf, class... ArgTypes>
void foo(OutType (MemberOf::*func)(ArgTypes...) const);

but how exactly do you combine the two function declarations above into one when it doesn't matter whether or not the input method is const?

Aucun commentaire:

Enregistrer un commentaire