Öncelikle yapılması gerekenler,
Visual Studio 2017, Tools -> NuGet Package Manager -> Package Manager Console -> “Install-Package cpplinq” yüklenmesini tamamlıyoruz.
Veya https://cpplinq.codeplex.com/downloads/get/817114 sayfasından dosyayı indirip, kullanabilirsiniz.
1 2 3 4 5 6 7 8 9 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 50 |
// // User.h // Cpp // // Created by Damra on 21/11/2017. // Copyright © 2017 Damra. All rights reserved. // #include <string> using namespace std; #ifndef User_h #define User_h struct User { string name; uint8_t nation; uint8_t level; uint16_t job; uint32_t loyalty; User(const string pName, uint8_t pNation, uint8_t pLevel, uint16_t pJob, uint32_t pLoyalty) { name = pName; nation = pNation; job = pJob; level = pLevel; loyalty = pLoyalty; } bool isKarus() { return nation == 1; } bool isWarrior() { vector <uint16_t> classes { 101, 201, 105, 205, 106, 206 }; return find(classes.begin(), classes.end(), job) != classes.end(); } bool isMasteredWarrior() { vector <uint16_t> classes{ 106, 206 }; return find(classes.begin(), classes.end(), job) != classes.end(); } void printInfo() { printf("Username : %s,\t Nation:%d,\t Job:%d,\t Level: %d,\t Loyalty:%d\n", name.c_str(), nation, job, level, loyalty); } }; #endif /* User_h */ |
1 2 3 4 5 6 7 8 9 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
// // main.cpp // Cpp // // Created by Damra on 21/11/2017. // Copyright © 2017 Damra. All rights reserved. // #include <iostream> #include <string> #include <list> #include <vector> #include "User.h" #include "cpplinq.hpp" using namespace std; using namespace cpplinq; list<User> userList; void loadUserList() { // Karus Warriors userList.push_back(User("Warrior", 1, 5, 101, 100)); userList.push_back(User("Berserker", 1, 58, 105, 4234)); userList.push_back(User("Berserker Hero", 1, 70, 106, 3412332)); // Karus Rogues userList.push_back(User("Rogue", 1, 5, 102, 100)); userList.push_back(User("Hunter", 1, 55, 107, 42344)); userList.push_back(User("Shadow Bane", 1, 70, 108, 1233414)); // Karus Wizards userList.push_back(User("Wizard", 1, 10, 103, 100)); userList.push_back(User("Sorcerer", 1, 45, 109, 50)); userList.push_back(User("Elemental Lord", 1, 70, 110, 10223220)); // Karus Priest userList.push_back(User("Priest", 1, 1, 104, 1200)); userList.push_back(User("Shaman", 1, 57, 111, 3423)); userList.push_back(User("Shadow Knight", 1, 70, 112, 34222223)); // Human Warriors userList.push_back(User("Warrior", 2, 5, 201, 3100)); userList.push_back(User("Blade", 2, 58, 205, 42324)); userList.push_back(User("Blade Master", 2, 70, 206, 99934)); // Human Rogues userList.push_back(User("Rogue", 2, 5, 202, 100)); userList.push_back(User("Ranger", 2, 55, 207, 42344)); userList.push_back(User("Kasar Hood", 2, 70, 208, 1233414)); // Human Wizards userList.push_back(User("Wizard", 2, 10, 203, 100)); userList.push_back(User("Mage", 2, 45, 209, 50)); userList.push_back(User("Arc Mage", 2, 70, 210, 102243220)); // Human Priest userList.push_back(User("Priest", 2, 1, 204, 100)); userList.push_back(User("Cleric", 2, 57, 211, 3423)); userList.push_back(User("Paladin", 2, 70, 212, 342222223)); } auto karusUsers = [](User pUser) { return pUser.isKarus(); }; auto warriors = [](User pUser) { return pUser.isWarrior(); }; auto masteredWarriors = [](User pUser) { return pUser.isMasteredWarrior(); }; auto over100kNP = [](User pUser) { return pUser.loyalty > 100000; }; auto over100kNPWarriors = [](User pUser) { return pUser.loyalty > 100000 && pUser.isWarrior(); }; int main(){ loadUserList(); string gg; cout << "size of userList:" << userList.size() << endl; // koşullu kullanımlar için örnek auto list1 = from(userList) >> where(karusUsers) >> to_list(); auto list2 = from(userList) >> where(warriors) >> to_list(); auto list3 = from(userList) >> where(masteredWarriors) >> to_list(); auto list4 = from(userList) >> where(over100kNP) >> to_list(); auto list5 = from(userList) >> where(over100kNPWarriors) >> to_list(); cout << endl << "size of karusUsers :" << list1.size() << endl; for(User pUser: list1){ pUser.printInfo(); }; cout << endl << "size of warriors :" << list2.size() << endl; for (User pUser : list2) { pUser.printInfo(); }; cout << endl << "size of masteredWarriors :" << list3.size() << endl; for (User pUser : list3) { pUser.printInfo(); }; cout << endl << "size of over 100k np :" << list4.size() << endl; for (User pUser : list4) { pUser.printInfo(); }; cout << endl << "size of over 100k np warriors:" << list5.size() << endl; for (User pUser : list5) { pUser.printInfo(); }; cin >> gg; } |
Çalıştırdıktan sonra console logda umduğumuz sonuç
1 2 3 4 5 6 7 8 9 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 |
size of userList:24 size of karusUsers :12 Username : Warrior, Nation:1, Job:101, Level: 5, Loyalty:100 Username : Berserker, Nation:1, Job:105, Level: 58, Loyalty:4234 Username : Berserker Hero, Nation:1, Job:106, Level: 70, Loyalty:3412332 Username : Rogue, Nation:1, Job:102, Level: 5, Loyalty:100 Username : Hunter, Nation:1, Job:107, Level: 55, Loyalty:42344 Username : Shadow Bane, Nation:1, Job:108, Level: 70, Loyalty:1233414 Username : Wizard, Nation:1, Job:103, Level: 10, Loyalty:100 Username : Sorcerer, Nation:1, Job:109, Level: 45, Loyalty:50 Username : Elemental Lord, Nation:1, Job:110, Level: 70, Loyalty:10223220 Username : Priest, Nation:1, Job:104, Level: 1, Loyalty:1200 Username : Shaman, Nation:1, Job:111, Level: 57, Loyalty:3423 Username : Shadow Knight, Nation:1, Job:112, Level: 70, Loyalty:34222223 size of warriors :6 Username : Warrior, Nation:1, Job:101, Level: 5, Loyalty:100 Username : Berserker, Nation:1, Job:105, Level: 58, Loyalty:4234 Username : Berserker Hero, Nation:1, Job:106, Level: 70, Loyalty:3412332 Username : Warrior, Nation:2, Job:201, Level: 5, Loyalty:3100 Username : Blade, Nation:2, Job:205, Level: 58, Loyalty:42324 Username : Blade Master, Nation:2, Job:206, Level: 70, Loyalty:99934 size of masteredWarriors :2 Username : Berserker Hero, Nation:1, Job:106, Level: 70, Loyalty:3412332 Username : Blade Master, Nation:2, Job:206, Level: 70, Loyalty:99934 size of over 100k np :7 Username : Berserker Hero, Nation:1, Job:106, Level: 70, Loyalty:3412332 Username : Shadow Bane, Nation:1, Job:108, Level: 70, Loyalty:1233414 Username : Elemental Lord, Nation:1, Job:110, Level: 70, Loyalty:10223220 Username : Shadow Knight, Nation:1, Job:112, Level: 70, Loyalty:34222223 Username : Kasar Hood, Nation:2, Job:208, Level: 70, Loyalty:1233414 Username : Arc Mage, Nation:2, Job:210, Level: 70, Loyalty:102243220 Username : Paladin, Nation:2, Job:212, Level: 70, Loyalty:342222223 size of over 100k np warriors:1 Username : Berserker Hero, Nation:1, Job:106, Level: 70, Loyalty:3412332 |