In C++17, the new map::extract
function lets you change the key.
Example:
std::map<int, std::string> m{ {10, "potato"}, {1, "banana"} };
auto nodeHandler = m.extract(10);
nodeHandler.key() = 2;
m.insert(std::move(nodeHandler)); // { { 1, "banana" }, { 2, "potato" } }
More Related Contents:
- Is there any advantage of using map over unordered_map in case of trivial keys?
- Sorting std::map using value
- A std::map that keep track of the order of insertion?
- Why Can’t I store references in a `std::map` in C++?
- Hashtable in C++?
- map with incomplete value type
- Converting std::__cxx11::string to std::string
- How to overload std::swap()
- Why is my program slow when looping over exactly 8192 elements?
- What is the efficient way to count set bits at a position or lower?
- Virtual functions and performance – C++
- How can I measure CPU time and wall clock time on both Linux/Windows?
- Why are Python Programs often slower than the Equivalent Program Written in C or C++?
- Is there any guarantee of alignment of address return by C++’s new operation?
- Explain Morris inorder tree traversal without using stacks or recursion
- Getting an accurate execution time in C++ (micro seconds)
- Can the use of C++11’s ‘auto’ improve performance?
- A fast method to round a double to a 32-bit int explained
- Is there a 128 bit integer in C++?
- What is the Fastest Method for High Performance Sequential File I/O in C++?
- Fastest way to get a positive modulo in C/C++
- Do c++ templates make programs slow?
- Using std::map where V has no usable default constructor
- How can I make the map::find operation case insensitive?
- std::remove_const with const references
- Why can’t I use a “break” statement inside a ternary conditional statement in C++?
- Syntax for using std::greater when calling std::sort in C++
- Simple for() loop benchmark takes the same time with any loop bound
- New (std::nothrow) vs. New within a try/catch block
- C++ most efficient way to convert string to int (faster than atoi)