when I try to insert in this map:
std::map<std::unordered_set<int >, std::pair<float, std::pair<float, float >> >
I got this error
error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::unordered_set,std::equal_to<_Kty>,std::allocator<_Kty>>'
My data is defined as follows:
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;
The part that has the problem:
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()));
S2[elem].second = std::make_pair(elem, Wesupp);
– Marco A.unordered_set
as keys?std::pair<float, std::pair<float, float>>
? (at least use astd::tuple
orstd::array<float, 3>
) – T.C.S2
I would like to insert theunordered_set
elem
with its three float values. every round in the loopelem
hasunordered_set
, if its similar to the previous one, I will update their three float values, otherwise I will insert newunordered_set
with its three float values. – Sandy