#include <map>
#include <iostream>
template <
template <class K, class V, class C, class A> class mapImpl,
class K,
class V,
class C=std::less<K>,
class A=std::allocator<std::pair<const K, V> >
>
class value_with_iterator {
public:
typedef typename mapImpl<const K,value_with_iterator,C,A>::iterator value_type;
value_type value;
};
typedef std::map<size_t, value_with_iterator <std::map, size_t, size_t> > map_size_t_to_itself;
map_size_t_to_itself::iterator insert(map_size_t_to_itself& mapRef, size_t value)
{
map_size_t_to_itself::value_type v(value, map_size_t_to_itself::mapped_type());
std::pair<map_size_t_to_itself::iterator, bool> res = mapRef.insert(v);
if (res.second)
res.first->second.value = res.first;
return res.first;
}
int main() {
map_size_t_to_itself mapObj;
map_size_t_to_itself::iterator i1 = insert(mapObj, 1);
map_size_t_to_itself::iterator i2 = insert(mapObj, 1);
map_size_t_to_itself::iterator i3 = insert(mapObj, 2);
std::cout << i1->first << ": " << i1->second.value->first << std::endl;
std::cout << i2->first << ": " << i2->second.value->first << std::endl;
std::cout << i3->first << ": " << i3->second.value->first << std::endl;
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPAogICAgdGVtcGxhdGUgPGNsYXNzIEssIGNsYXNzIFYsIGNsYXNzIEMsIGNsYXNzIEE+IGNsYXNzIG1hcEltcGwsIAogICBjbGFzcyBLLCAKICAgY2xhc3MgViwgCiAgIGNsYXNzIEM9c3RkOjpsZXNzPEs+LCAKICAgY2xhc3MgQT1zdGQ6OmFsbG9jYXRvcjxzdGQ6OnBhaXI8Y29uc3QgSywgVj4gPgo+CmNsYXNzIHZhbHVlX3dpdGhfaXRlcmF0b3IgewpwdWJsaWM6CiAgIHR5cGVkZWYgdHlwZW5hbWUgbWFwSW1wbDxjb25zdCBLLHZhbHVlX3dpdGhfaXRlcmF0b3IsQyxBPjo6aXRlcmF0b3IgdmFsdWVfdHlwZTsKICAgdmFsdWVfdHlwZSB2YWx1ZTsKfTsKCnR5cGVkZWYgc3RkOjptYXA8c2l6ZV90L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