I have the following map type…
std::map<D3DXCOLOR, ID3DXMesh*>
During compilation, xfunctional complains that it cannot resolve an ambiguity regarding the key type;
error C2593: 'operator <' is ambiguous
The candidate operators detected by the compiler are as follows;
- built-in C++ operator<(DWORD, DWORD)
- built-in C++ operator<(FLOAT, FLOAT)
- built-in C++ operator<(D3DCOLORVALUE, D3DCOLORVALUE)
The D3DXCOLOR struct consists of 4 floats r, g, b, and a respectively but does not define a operator <. It does however provide cast functions for DWORD FLOAT and D3DCOLORVALUE, hence the entries in the candidate list.
I am contemplating the best way to resolve this problem. I could write my own inline operator for D3DXCOLOR, wrap the colour inside a new class which provides its own operator <, or is it possible to somehow hint to the compiler which implementation should be chosen from the list of candidates? The DWORD operator < would meet my requirements adequately.
You have three options. Supposing for example that you want them compared as colorvalues:
1) Define
operator<:2) Specialize
std::less:3) Supply a third template parameter to your map – note that this changes the type of the map, so if you pass the map around a lot this might be inconvenient. But it expresses that the ordering is to be used only for this map, not as the canonical “correct” order of colors for any other purpose.