Skip to content

Instantly share code, notes, and snippets.

@BillyONeal
Created April 17, 2019 03:04
Show Gist options
  • Save BillyONeal/4e0ad2d6f3f2e383867ba5b497001cc8 to your computer and use it in GitHub Desktop.
Save BillyONeal/4e0ad2d6f3f2e383867ba5b497001cc8 to your computer and use it in GitHub Desktop.
Megaderp
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
#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