- 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
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
int main()
{
using namespace std::placeholders;
std::map<std::string, int> karta;
std::vector<std::string> goroda{ "foo", "bar", "foo" };
std::for_each(goroda.begin(), goroda.end(), std::bind(
static_cast<
std::pair<decltype(karta)::iterator, bool>
(decltype(karta)::*)(const decltype(karta)::key_type&, decltype(karta)::mapped_type&&)>
(&decltype(karta)::insert_or_assign),
std::ref(karta),
_1,
std::bind(
std::plus<decltype(karta)::mapped_type>(),
1,
std::bind(
static_cast<decltype(karta)::mapped_type&(decltype(karta)::*)(const decltype(karta)::key_type &)>
(&decltype(karta)::operator[]),
std::ref(karta),
_1))
));
std::cout << "foo: " << karta["foo"] << "\nbar: " << karta["bar"] << '\n';
return EXIT_SUCCESS;
}