当我尝试在此地图中插入时:
std::map<std::unordered_set<int >, std::pair<float, std::pair<float, float >> >
我收到了这个错误
错误 C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : 无法推导出 'const std::_Tree<_Traits> &' 的模板参数从 'const std::unordered_set,std::equal_to<_Kty>,std::allocator<_Kty>>'
我的数据定义如下:
struct Trans {
int Item;
float Prob;
float W;
};
bool operator<(const Trans &a, const Trans &b)
{
return a.Item < b.Item;
}
bool operator==( Trans c, Trans d) { return c.Item == d.Item; }
struct MyHash {
size_t operator()(const Trans& x) const { return std::hash<int>()(x.Item); }
};
std::vector<std::vector<Trans>> data;
std::map<std::unordered_set<int>, float> S1;
std::map<std::unordered_set<int >, std::pair<float, std::pair<float, float >> > S2;
std::map<std::unordered_set<int >, std::pair<float, std::pair<float, float >> > S3;
有问题的部分:
do
{
std::unordered_set<Trans, MyHash> KS(data[i].begin(), data[i].begin() + k);
std::unordered_set<int > elem;
float esupp = 1;
float Weight = 0;
float Wesupp = 1;
for (auto const &iter : KS)
{
elem.insert(iter.Item);
esupp *= iter.Prob;
Weight += iter.W;
}
Weight = Weight / k;
/*
some code, and until here I didn't get any problem
*/
**// This the area that has the problem**
S1[elem] = std::move(S1[elem] + esupp);
Wesupp = Weight * S1[elem];
S2[elem].first = std::move(S2[elem].first + esupp);
S2[elem].second = std::make_pair(elem, Wesupp);
} while (next_combination(data[i].begin(), data[i].begin() + k, data[i].end()));