Skip to content

Instantly share code, notes, and snippets.

@ExtremeFine21
Created January 13, 2026 03:37
Show Gist options
  • Select an option

  • Save ExtremeFine21/bbf2bde379e30000aa23cbe835722b1b to your computer and use it in GitHub Desktop.

Select an option

Save ExtremeFine21/bbf2bde379e30000aa23cbe835722b1b to your computer and use it in GitHub Desktop.
Лямбда - функции
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main() {
list<int> lst = {1, 2, 4, 7, 10, 13};
vector<int> v = {5, -2, 8, -1, 0, 6};
vector<string> words = {"meet", "sea", "son", "night"};
auto evenCount = count_if(lst.begin(), lst.end(),
[](int x) { return x % 2 == 0; });
cout << evenCount << endl;
for_each(v.begin(), v.end(),
[](int x) {
if (x % 2 == 0)
cout << x << " ";
});
cout << endl;
v.erase(remove_if(v.begin(), v.end(),
[](int x) { return x < 0; }), v.end());
for (int x : v) cout << x << " ";
cout << endl;
char letter = 's';
auto countByLetter = count_if(words.begin(), words.end(),
[letter](const string& s) {
return !s.empty() && s[0] == letter;
});
cout << countByLetter << endl;
map<char, int> result;
for_each(words.begin(), words.end(),
[&result](const string& s) {
if (!s.empty())
result[s[0]]++;
});
for (auto& p : result)
cout << p.first << " - " << p.second << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment