- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
#include <iostream>
#include <map>
template <typename T1, typename T2, typename F>
void operator ^= (std::map<T1,T2> &m, F func) {
for (typename std::map<T1,T2>::iterator i = m.begin(); i != m.end(); ) {
if (func(i))
i = m.erase(i);
else
++i;
}
}
template <typename T1, typename T2>
void operator ^= (std::map<T1,T2> &m, T2 value) {
for (typename std::map<T1,T2>::iterator i = m.begin(); i != m.end(); ) {
if (value == i->second)
i = m.erase(i);
else
++i;
}
}
int main() {
std::map<int,bool> m = {
{0,false},
{1,true},
{2,false},
{3,true},
{4,false},
{5,true},
{6,false},
{7,true},
{8,false},
{9,true},
{10,false}
};
for (auto i = m.begin(); i != m.end(); ++i)
std::cout << "{" << i->first << "," << i->second << "} ";
std::cout << std::endl;
m ^= false;
m ^= [](auto &i) { return i->first == 5; };
for (auto i = m.begin(); i != m.end(); ++i)
std::cout << "{" << i->first << "," << i->second << "} ";
std::cout << std::endl;
}