samedi 25 février 2017

Custom std::set comparator with compound types

This is related to my previous question regarding templates, that I managed to make work. I tried a more complex example:

template <typename T>
struct Cmp{
    bool operator() (const set<typename set<Node <T>>::iterator, Cmp<T>>, Cmp<T>& lhs, const set<typename set<Node <T>>::iterator, Cmp<T>>, Cmp<T> &rhs) {
        return true;
    }

    bool operator() (const set<typename set<Node <T>>::iterator, Cmp<T>>, Cmp<T>& lhs, const unsigned& rhs) {
        return true;
    }
};

template <typename T>
class Graph {

private:
    set<set<typename set<Node <T>>::iterator, Cmp<T>>, Cmp<T>> cliques = ;
};

Node is a template class. I only instantiate the Graph class once, with <int>, but I get the following compilation error:

error: no match for call to 
(Cmp<int>) (const std::set<std::_Rb_tree_const_iterator<Node<int> >, Cmp<int>, std::allocator<std::_Rb_tree_const_iterator<Node<int> > > >&, const key_type&)
    && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))

I have seemingly tried about every possible prototypes for the functions in Cmp. The error seems to be that operator() (const set<set<Node<int>>::const_iterator, Cmp<int>>&, const key_type&) is not defined. However, assuming that key_type is the type of the values stored in the set, the override I have provided above should work.

What is missing from my code?

Aucun commentaire:

Enregistrer un commentaire