thinktwice wrote:
Quote:
thanks, i have customize the compare function, but seems it doesn't
work. is there anything wrong?
>
struct myVariantCompare{
inherit from binary_function
Quote:
bool operator()(VARIANT v1, VARIANT v2)
this should be const
Quote:
{
if (v1.vt == v2.vt)
{
if (v1.vt == VT_UNKNOWN)
{
why not assert here instead and loose the branch?
Quote:
CComPtr<IUnknownspUnk1(v1.punkVal);
if (spUnk1.IsEqualObject(v2.punkVal))
{
return false;
}
else
{
return v1.punkVal < v2.punkVal;
there is obviously a '<' operator for VARIANT::punkVal
therefore there is an equivalent for '=' operator too
so the spUnk1 seems superfluous.
I don't know COM and have no idea why you write it this way
Quote:
}
}
else
{
//assert, don't support other types
this branch doesn't return
Quote:
}
}
else
{
return v1.vt < v2.vt;
}
}
>
>
};
>
>
typedef std::multimap<CComVariant, long , _myVariantComparemyMap;
I suppose CComVariant and VARIANT are the same type
Quote:
typedef myMap::iterator myIter;
myMap map0;
>
is there any problem with my compare function?
to simplify:
change VARIANT with pair
bool operator()(pair const & v1, pair const & v2) const
{
if(v1.first == v2.first)
{
if(v1.second == v2.second)
return false;
else
return v1.second < v2.second;
}
else
return v1.first < v2.first;
}