stl - C++ std::copy from std::deque to std:;set -


i have class "array of array" private member represented as:

std::deque<std::deque<someclass> > somearray_; 

also class have public method allows receive unique someclass instances, containing in somearray_. unique someclass instances means different @ least 1 of several class members. decided use std::set purpose. method has prototype following:

std::set<someclass> getalluniqueinstances() const; 

in method implementation use following construction populate std::set:

std::set<someclass> alluniqueinstances; for(auto = std::begin(somearray_); != std::end(somearray_); ++it){     std::copy((*it).begin(),                (*it).end(),               std::inserter(alluniqueinstances, alluniqueinstances.end())); } 

operator<() defined someclass class. result std::set populated, huge amount of instances missed. modyfing operator<() someclass class, alters situation, breaks desirable sorting order. how in case std::copy determines whether considerable instance unique?

upd: source code someclass

class someclass{     private:         uint32_t from_;         uint32_t to_;         double capacity_;         double flow_;     public:                 ...         bool operator<(const someclass& rhs) const;         ...     }; 

i want someclass instances ordered in set from_ member:

bool someclass::operator<( const someclass& rhs ) const{     if(this->from_ < rhs.from_)         return true;         return false;     } 

it not std::copy decides whether instances unique, std::set. logic like

(a < b false) , (b < false)

so criterion defines ordering defines "uniqueness". seems std::set wrong data structure problem, or ordering criteria either incorrect (as in not implementing strict weak ordering), or broad suit problem (as in, order based on small number of attributes when use more).

here example of lexicographical comparison using more attributes have:

#include <tuple> // std::tie  bool someclass::operator<( const someclass& rhs ) const {   return std::tie(from_, to_, capacity_, flow_) < std::tie(rhs.from_, rhs.to_, rhs.capacity_, rhs.flow_); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -