Created
October 7, 2014 02:13
-
-
Save make-github-pseudonymous-again/2f88f77d89f8707bea12 to your computer and use it in GitHub Desktop.
en.cppreference.com example for emplace construction in unordered maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <utility> | |
#include <unordered_map> | |
int main(){ | |
std::unordered_map<std::string, std::string> m; | |
// uses pair's copy-constructor | |
m.emplace(std::make_pair(std::string("a"), std::string("a"))); | |
// uses pair's converting copy constructor | |
m.emplace(std::make_pair("b", "abcd")); | |
// uses pair's template constructor | |
m.emplace("d", "ddd"); | |
// uses pair's piecewise constructor | |
m.emplace(std::piecewise_construct, | |
std::forward_as_tuple("c"), | |
std::forward_as_tuple(10, 'c')); | |
for (const auto &p : m) { | |
std::cout << p.first << " => " << p.second << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment