jeudi 3 mars 2016

How to get reference to inserted object from std::map::emplace()?

How to get reference to inserted object from std::map::emplace()? Official doc for emplace. I have added auto inserted = m.emplace("d", "ddd");

Can you please demonstrate how to get reference to just inserted "ddd"?

I receive some ridiculus type struct std::_Rb_tree_iterator and cannot find any documentation or example how to work with it.

#include <iostream>
#include <utility>
#include <string>

#include <map>
int main()
{
    std::map<std::string, std::string> m;

    // uses pair's template constructor
    auto inserted = m.emplace("d", "ddd");

    for (const auto &p : m) {
        std::cout << p.first << " => " << p.second << '\n';
    }
}

Aucun commentaire:

Enregistrer un commentaire