vendredi 2 octobre 2015

Using pair in variadic templates

Okay, I'm trying to implement a range tree in n-dimensions using variadic templates. I have the basic setup working, but I want to be able to optionally pass a compare function object in the template list to sort the tree by something other than std::less.

My first thought is that I could overload the template list with a version that includes a pair as the first element, with the pair containing the type and the compare funcition. But I can't see to get the template declaration line to compile. Visual C++ (2015) starts with C2079: "std::pair::first uses undefined class 'T'".

Anyways, on to the code. Here's a small snippet to show what I'm trying to do:

template <class... Args> class rangetree{
};

template <class T, class... Args> class rangetree<T, Args...> {
public:
  map <T, rangetree<Args...> * > tree;
};

This all works normally. But when I add another version of rangetree, with a pair as the first template member, I have problems:

template <pair<class T, class Compare>, class... Args> class rangetree<pair<T, Compare>, Args...>{
public:
  map <T, rangetree <Args...> *, Compare> tree;
};

This is the part I can seem to get formatted in a way that the compiler is happy. The idea is to optionally pair template members with compare functions if something other than less should be used.

Aucun commentaire:

Enregistrer un commentaire