I’m working with pointer-to-member types inside templates, currently I have something like this going on:
template <typename Base, typename Type, Type Base::* Var>
struct Member
{
//Stuff goes here.
};
But having to define Base, Type, and then Var, seems a little redundant, since Base and Type are implied in Var’s type.
Is there some way to do this, such that, when using/calling the Member struct, it only needs to use the single pointer-to-member argument? Like, in theory, something like this:
template <typename Base, typename Type, Type Base::* Var>
struct Member<Var>
{
//stuff goes here
};
struct S
{
int memberVal;
};
int main()
{
Member<&S::memberVal> example;
};
Thanks for the help!
No way. Only your first variant is correct. You are giving example where the C++ cyntax is not that elegant. Bit it is as it is.
Your second example has syntax of a template specialization. While it is definition of a new template. Most likely this will be put as an objection.