std::map error: cant apply < to struct

hi, i want to generate a new type (struct) A. it has only 1 member variable:

map< X, list<Y> > mappedvalues;

X and Y are simple struct which can be default constructed.
what am i missing ?

compiler: Visual Studio 2017

the error i get is:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2678

i can generate a value:
pair<X, list<Y> value;

but i cant add it to the mappedvalues above, why ? how can i fix that ?
i'm doing that in a recursive function call which takes A& as an arguement.
Last edited on
The key types must be comparable using std::less (by default) . std::map is a sorted container.

You can fix it by supplying a total order for X, either via a comparison functor or by defining bool operator<(X const&, X const&), or some flavor thereof.

Edit:
This would be easier to explain if you actually posted some code.
Last edited on
finally i solved it. first i overloaded operator <, but that lead to different A key values being mapped to the same map key, so i added a "unique" function to distinguish between values more explicit:

1
2
3
4
5
6
7
float __Unique() const {
		return .. some.calculation.here..;
	}

	bool operator<(const A& other) const {
		return __Unique() < other.__Unique();
	}
Last edited on
Topic archived. No new replies allowed.