So, I have an array (0 - n) containing the values ββthat I want to use std :: set to sort it. An unsigned array of int cost [n].
I use the following functor for this sort:
struct ProxySorter { ProxySorter(const unsigned* arr) : proxy_array(arr) {} bool operator()(const unsigned& a, const unsigned& b) const { return proxy_array[a] < proxy_array[b]; } const unsigned* proxy_array; };
So, here is the problem ... When I create a set, it is legal:
std::set<unsigned, ProxySorter> node_queue = std::set<unsigned, ProxySorter>(ProxySorter(cost));
I get no errors and everything works as expected. But it seems hacky and messy.
However, this is apparently illegal:
std::set<unsigned, ProxySorter> node_queue(ProxySorter(cost));
Trying to simply construct it using ProxySorter (cost) causes a lot of errors saying such things for every call to a set of elements:
error: request to delete an element in node_queue that is of type non-class std :: set <unsigned int, ProxySorter> (ProxySorter)
What is the problem with the usual design? Why does the job work? What is the difference here that I am missing? Any help is greatly appreciated, thanks.
Oh, and sorry about the title of the question, I was not sure what to call it.
c ++ set constructor stl predicate
Robert Kelly
source share