c++11 - How to declare templated pointer to templated method? -
templated typedef
s possible using
. how can directly make templated method pointer?
example:
class myclass { template<bool b> void fnc() { /*...*/ }; // can do: template<bool b> using tempptr = decltype(&myclass::fnc<b>); // ^^^^^^^^^^^^^^^^^^^^^^^^^^ };
how can write underlined part direcly, without decltype
?
so far, have tried:
template<bool b> using tempptr = template<bool> void (myclass::*)(); template<bool b> using tempptr = void (myclass::*<b>)(); ...
(follow question: can use tempptr
as template template parameter?)
those work, giving different behaviour:
template<bool b> using ptr = void (myclass::*)(); using ptr2 = void (myclass::*)(); // alternatively //typedef void (myclass::*ptr2)();
to use:
myclass::ptr<true> ptr = &myclass::fnc<true>; myclass::ptr2 ptr2 = &myclass::fnc<true>;
the bool parameter in ptr
isn't same parameter in fnc
. since template type isn't part of signature, mismatch bind fine, utilized other purposes:
myclass::ptr<false> ptr = &myclass::fnc<true>;
that's why nontemplated ptr2
works fine.
Comments
Post a Comment