mercredi 2 décembre 2015

C++ std::sort of const struct

I have the following struct in a vector

struct ub_node {
    const size_t index;
    const double ub_dist;
    bool operator<(const ub_node &rhs) const { return ub_dist< rhs.ub_dist; }
};

I would like to sort that vector. I have tried using std::sort but I get a compile error: error: use of deleted function ‘ub_node& ub_node::operator=(ub_node&&)’ with a reference to the line where I do std::sort(result.begin(), result.end());, where result is of type vector<ub_node>.

As far as I understand, the const does NOT affect the execution time, but merely ensures that the programmer (me) does not do anything stupid. If this is the case, I might remove the const and try to ensure that I do not change the node afterwards. Can someone confirm this? Or help me to sort it?

Aucun commentaire:

Enregistrer un commentaire