lundi 2 janvier 2017

Function template return type deduction

I have some class C with const and non-const getters for some generic type Node:

template <typename NodeType>
class CParent{};

class Node {};

class C : public CParent<Node> {
    Node&       getNode(Index i);
    const Node& getNode(Index i) const;
};

Now I want to create an alias function that call getNode for an object of class C:

template <class CType>
NodeType& AliasGetNode(CType* cobject);

But how do I deduce NodeType? i.e., if I call AliasGetNode<const C>(c) and AliasGetNode<C>(c), NodeTypeshould be respectively const Node&and Node&.

How can I do this?

I tried the result_of and decltypeapproacehes but have not been successful.

Aucun commentaire:

Enregistrer un commentaire