c++ - "Don't Care" fields in multiset keys -
i have compound data type like:
struct key { optional<int> a; optional<int> b; optional<int> c; };
i have multiset, multiset<key>
. example, contains
{1, 2, 3} {1, null, 3} {null, 2, 3} {null, null, 3}
i want objects in multiset match {1, 2, 3}
. there catch: null
fields should match anything. example, {1, 2, 3}
matches {1, null, 3}
.
i tried defined comparator (<
) ignores null values. example {1, null, null} == {null, 2, 3}
. not follow weak strict ordering , gives me wrong results.
how can that?
your problem here more serious not following weak strict ordering rules. equality not equivalence relation: { 1,null,3} matches {1, 2, 3} , {1, 4, 3}, {1, 2, 3} not match {1, 4, 3}. conclusion cannot rely on standard container meet matching requirement catch all values.
if want store them, should try use unordered_set
or unordered_multiset
because allow store value without problems. have manually implement method searching container match.
beware: not advise subclass standard container (it wrong idea because not designed allow derivation, have no virtual destructor...), instead include 1 in custom class , delegate storage it.
Comments
Post a Comment