I have this structure
static map<TypeA, pair<reference_wrapper<TypeB>, TypeC>> my_map;
Later, I access it like this:
pair<reference_wrapper<TypeB>, TypeC> instance = my_map[type_a_instance];
This error triggers:
no matching function for call to 'std::pair<std::reference_wrapper< TypeB>, TypeC>::pair()'
map::operator[]must default construct the pair in the map if no mapping for the key exists. That's not possible for the types in your map because of thereference_wrapper. Usefindinstead.Or use
atas suggested by @Steve LorimerOf course both versions assume that the key can be found. The
findversion gives you undefined behaviour if the key is not found, theatversion gives astd::out_of_rangeexception.