简体   繁体   中英

How to create template class with member function pointer?

Is anyone knows how to declare generalized template form for the next template specialization:

template <template <class> class Container,
          class Value,
          class Return,
          Return (Container<Value>::*Apply)(const Value &)>
class Example<Container<Value>, Apply>
{

};

Apply must be a pointer to a member function whoes signature is unknown in template declaration.

Do you mean something like this?

template<typename T, typename F>
struct S;

template<template <typename...> class C, typename R, typename... A>
struct S<C<A...>, R(A...)> {
    using Apply = R(C<A...>::*)(A...);
     // ...
};

As an example:

template<typename... U>
struct T {
    int f(int, char) { return 42; }
};

template<typename T, typename F>
struct S;

template<template <typename...> class C, typename R, typename... A>
struct S<C<A...>, R(A...)> {
    using Apply = R(C<A...>::*)(A...);
     // ...
};

int main() {
    S<T<int, char>, int(int, char)>::Apply apply = &T<int, char>::f;
}

Pretty ugly, indeed, but that's what the OP (maybe) asked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM