c++ set and shared_ptr -
i have class x like:
class x { public: bool operator<(const scn& other) const; };
the have following code
std::multiset<std::shared_ptr<x>> m;
my questions are:
- how data in m ordered? address of x(shared_ptr) or x.operator
for m, if want access elements smallest bigest, can following code grantee that? if not, how?
for (auto& : m) { f(i); }
your set ordered based on key_type std::shared_ptr<x>
. std::shared_ptr<x>
comparable, ordering of std::shared_ptr prevails.
for sake of reference, multiset defined as
template< class key, class compare = std::less<key>, class allocator = std::allocator<key> > class multiset;
as can seen, typename compare
std::less<key>
, std::less should overload function overload possibly implemented as
constexpr bool operator()(const t &lhs, const t &rhs) const { return lhs < rhs; }
both lhs
, rhs
of type t
in case key
type have instantiated multiset std::shared_ptr<x>
.
Comments
Post a Comment