Created
April 17, 2019 03:04
-
-
Save BillyONeal/4e0ad2d6f3f2e383867ba5b497001cc8 to your computer and use it in GitHub Desktop.
Megaderp
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
C:\Users\billy\Desktop>cl /EHsc /W4 /WX .\test.cpp && .\test.exe | |
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27607.1 for x86 | |
Copyright (C) Microsoft Corporation. All rights reserved. | |
test.cpp | |
Microsoft (R) Incremental Linker Version 14.20.27607.1 | |
Copyright (C) Microsoft Corporation. All rights reserved. | |
/out:test.exe | |
test.obj | |
actual: | |
{0, 0} | |
{1, 0} | |
{2, 0} | |
{3, 4} | |
{3, 0} | |
{3, 1} | |
{3, 2} | |
{3, 3} | |
{4, 0} | |
{5, 0} | |
{6, 0} | |
expected: | |
{0, 0} | |
{1, 0} | |
{2, 0} | |
{3, 0} | |
{3, 1} | |
{3, 2} | |
{3, 3} | |
{3, 4} | |
{4, 0} | |
{5, 0} | |
{6, 0} | |
fail |
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
#include <map> | |
#include <algorithm> | |
#include <stdio.h> | |
using namespace std; | |
void print_map(const std::multimap<int, int>& m) { | |
for (const pair<const int, int>& p : m) { | |
printf("{%d, %d}\n", p.first, p.second); | |
} | |
} | |
int main() { | |
multimap<int, int> m{ | |
{0, 0}, | |
{1, 0}, | |
{2, 0}, | |
{3, 1}, | |
{3, 2}, | |
{3, 3}, | |
{4, 0}, | |
{5, 0}, | |
{6, 0}, | |
}; | |
// Standard: The element is inserted as close as possible to the position just prior to p. | |
m.emplace_hint(next(m.begin()), 3, 0); // should insert at the beginning of the 3s | |
m.emplace_hint(prev(m.end()), 3, 4); // should insert at the end of the 3s | |
const multimap<int, int> expected{ | |
{0, 0}, | |
{1, 0}, | |
{2, 0}, | |
{3, 0}, | |
{3, 1}, | |
{3, 2}, | |
{3, 3}, | |
{3, 4}, | |
{4, 0}, | |
{5, 0}, | |
{6, 0}, | |
}; | |
puts("actual:"); | |
print_map(m); | |
puts("expected:"); | |
print_map(expected); | |
puts(equal(m.begin(), m.end(), expected.begin(), expected.end()) ? "pass" : "fail"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment