Вот демо -код:
Код: Выделить всё
#include
using namespace std;
std::map a = {{1, 1}};
int* set_and_return_value() {
// option 1: a[1] = 2; return &(a[1]); i think it's ugly
const auto [it, ok] = a.emplace(1, 2);
return &(it->second);
// emplace is good, but it won't modify the existed key's value
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... e-iterator
Мобильная версия