Created
August 1, 2020 06:02
-
-
Save crcrpar/cfa53f8dc7a1218f561549f1f3fd5897 to your computer and use it in GitHub Desktop.
This file contains 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
// Type your code here, or load an example. | |
#include <string> | |
#include <map> | |
using namespace std; | |
// https://youtu.be/hEx5DNLWGgA?t=4261 | |
void f(void) { | |
map<int, string> m = {{1, "one"}, {2, "two"}}, m2; | |
m.insert(m2.begin(), {3, "three"}); // should be error | |
m.insert(m.begin(), {3, "three"}); // ok, m.begin() points to m | |
m.insert(m.begin(), m.end()); // 2 ERRORS: (1) params point to m, and (2) m is modifiable by m.insert | |
m.insert(m2.begin(), m.end()); // ERROR param1 points to m2, but param2 points to m | |
m.insert(m2.begin(), m2.end()); // OK, params point to m2, m2 not modifiable by m.insert | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment