- // Type your code here, or load an example.
- #include <format>
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <functional>
- // #include <filesystem>
- using namespace std;
- struct FileInfo {
- string Name; // Name der Datei
- long long Length; // Dateigröße
- };
- struct MySmaler {
- bool operator () (const std::string & a, const std::string & b){
- return a < b;
- };
- };
- struct MyGrater {
- bool operator () (const FileInfo & a, const FileInfo & b){
- return a.Length < b.Length;
- };
- };
- bool greaterFile( FileInfo * pA, FileInfo * pB ) {
- return pA->Length < pB->Length;
- }
- void test()
- {
- std::vector<std::string> vi{ "Du", "Wir", "Lila", "Alle", "Andren"};
- std::sort(vi.begin(), vi.end(), std::greater<std::string>());
- int tütÖÄ = 42;
- for( auto x : vi ) {
- std::cout << x << " ";
- }
- std::cout << std::endl;
- std::sort(vi.begin(), vi.end(), MySmaler());
- for( auto x : vi ) {
- std::cout << x << " ";
- }
- std::cout << "\nFiles (" << tütÖÄ << "):\n";
- std::vector<FileInfo> vf {{"aa", 1234}, {"bbb", 4711}, {"LauneBär", 123456789012}};
- std::sort(vf.begin(), vf.end(), MyGrater());
- for( auto f : vf ) {
- std::cout << f.Name << ": " << f.Length << endl;
- }
- std::cout << std::endl;
- std::vector<FileInfo *> vpf;
- std::sort(vpf.begin(), vpf.end(), greaterFile);
- [](int i) {cout << i << endl; }(5);
- [tütÖÄ](const char * name) { cout << "lambda - " << name << " : " << tütÖÄ << endl; } ( "jaja");
- std::function<void()> f1 = []() {cout << "a" << endl; } ;
- std::function<void(void)> f2 = []() {cout << "b" << endl; } ; ;
- std::function<int(int x, std::string y)> f3 = [](int x, std::string s ) {cout << x << " - " << s << endl; return x; };
- std::function<std::string(int x)> f4 = [](int x ) {cout << x << " - " << endl; return string("Hallo"); };
- std::function<std::string(int x, std::function<std::string(int)>)> f5 = [](int x, std::function<std::string(int)> _fx ) {cout << x << " - " << _fx(x) << endl; return _fx(x); };
- f1();
- f2();
- cout << f3(23, "Testen macht Spass!!") << endl;
- cout << f5(42, f4) << endl;
- }
- int main() {
- test();
- return 0;
- }
Sioggis Mist.
Posted by Anonymous on Tue 19th Nov 2024 16:09
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.