Say I have a custom type in my set, and the set/ordering only makes sense if all items have the same value on some property… if an item with a different value is inserted the model is screwed up and I want to protect this.
I thought maybe the comparison function might be a place we could test this (as an assert or exception) to either flag the problem and/or prevent the item getting inserted. e.g on TypeName, operator<() always returns false if the important attribute isn’t equal.
Is this reasonable?
I guess putting it in the comparator could have issues as you’ve not got any guarantees when it’s going to be called. Perhaps some mythical implementation stores items in a list when the number of items is small and doesn’t call the comparator until later?
Probably the simplest approach would be to wrap the
std::setin a protective outer class that performed these assertions.}