

| LINQ methods | Relinx methods |
|---|---|
| Aggregate | aggregate |
| All | all |
| none | |
| Any | any |
| AsEnumerable | from |
| Avarage | avarage |
| Cast | cast |
| Concat | concat |
| Contains | contains |
| Count | count |
| cycle | |
| DefaultIfEmpty | default _ if _ empty |
| Distinct | distinct |
| ElementAt | element_at |
| ElementAtOrDefault | element_at_or_default |
| Empty | from |
| Except | except |
| First | first |
| FirstOrDefault | first_or_default |
| for_each , for_each_i | |
| Groupby | group_by |
| Groupjoin | group_join |
| Intersect | intersect_with |
| Join | join |
| Last | last |
| LastOrDefault | last_or_default |
| Longcount | count |
| Max | max |
| Min | min |
| OfType | of_type |
| Orderby | order_by |
| OrderByDescending | order_by_descending |
| Range | range |
| Repeat | repeat |
| Reverse | reverse |
| Select | select, select_i |
| SelectMany | select_many , select_many_i |
| SequenceEqual | sequence_equal |
| Single | single |
| SingleOrDefault | single_or_default |
| Skip | skip |
| Skipwhile | skip_while, skip_while_i |
| Sum | sum |
| Take | take |
| TakeWhile | take_while, take_while_i |
| ThenBy | then_by |
| ThenByDescending | then_by_descending |
| ToArray | to_container, to_vector |
| ToDictionary | to_map |
| Tolist | to_list |
| ToLookup | to_multimap |
| to_string | |
| Union | union_with |
| Where | where, where_i |
| Zip | zip |
auto result = from({1, 2, 3, 4, 5, 6, 7, 8, 9})->count([](auto &&v) { return !!(v % 2); }); std::cout << result << std::endl; // : 5 struct Customer { uint32_t Id; std::string FirstName; std::string LastName; uint32_t Age; bool operator== (const Customer &other) const { return Id == other.Id && FirstName == other.FirstName && LastName == other.LastName && Age == other.Age; } }; //auto group_by(KeyFunction &&keyFunction) const noexcept -> decltype(auto) std::vector<Customer> t1_data = { Customer{0, "John"s, "Doe"s, 25}, Customer{1, "Sam"s, "Doe"s, 35}, Customer{2, "John"s, "Doe"s, 25}, Customer{3, "Alex"s, "Poo"s, 23}, Customer{4, "Sam"s, "Doe"s, 45}, Customer{5, "Anna"s, "Poo"s, 23} }; auto t1_res = from(t1_data)->group_by([](auto &&i) { return i.LastName; }); auto t2_res = from(t1_data)->group_by([](auto &&i) { return std::hash<std::string>()(i.LastName) ^ (std::hash<std::string>()(i.FirstName) << 1); }); assert(t1_res->count() == 2); assert(t1_res->first([](auto &&i){ return i.first == "Doe"s; }).second.size() == 4); assert(t1_res->first([](auto &&i){ return i.first == "Poo"s; }).second.size() == 2); assert(from(t1_res->first([](auto &&i){ return i.first == "Doe"s; }).second)->contains([](auto &&i) { return i.FirstName == "Sam"s; })); assert(from(t1_res->first([](auto &&i){ return i.first == "Poo"s; }).second)->contains([](auto &&i) { return i.FirstName == "Anna"s; })); assert(t2_res->single([](auto &&i){ return i.first == (std::hash<std::string>()("Doe"s) ^ (std::hash<std::string>()("John"s) << 1)); }).second.size() == 2); assert(t2_res->single([](auto &&i){ return i.first == (std::hash<std::string>()("Doe"s) ^ (std::hash<std::string>()("Sam"s) << 1)); }).second.size() == 2); struct Customer { uint32_t Id; std::string FirstName; std::string LastName; uint32_t Age; bool operator== (const Customer &other) const { return Id == other.Id && FirstName == other.FirstName && LastName == other.LastName && Age == other.Age; } }; struct Pet { uint32_t OwnerId; std::string NickName; bool operator== (const Pet &other) const { return OwnerId == other.OwnerId && NickName == other.NickName; } }; //auto group_join(Container &&container, ThisKeyFunction &&thisKeyFunction, OtherKeyFunction &&otherKeyFunction, ResultFunction &&resultFunction, bool leftJoin = false) const noexcept -> decltype(auto) std::vector<Customer> t1_data = { Customer{0, "John"s, "Doe"s, 25}, Customer{1, "Sam"s, "Doe"s, 35}, Customer{2, "John"s, "Doe"s, 25}, Customer{3, "Alex"s, "Poo"s, 23}, Customer{4, "Sam"s, "Doe"s, 45}, Customer{5, "Anna"s, "Poo"s, 23} }; std::vector<Pet> t2_data = { Pet{0, "Spotty"s}, Pet{3, "Bubble"s}, Pet{0, "Kitty"s}, Pet{3, "Bob"s}, Pet{1, "Sparky"s}, Pet{3, "Fluffy"s} }; auto t1_res = from(t1_data)->group_join(t2_data, [](auto &&i) { return i.Id; }, [](auto &&i) { return i.OwnerId; }, [](auto &&key, auto &&values) { return std::make_pair(key.FirstName + " "s + key.LastName, from(values). select([](auto &&i){ return i.NickName; }). order_by(). to_string(",")); } )->order_by([](auto &&p) { return p.first; })->to_vector(); assert(t1_res.size() == 3); assert(t1_res[0].first == "Alex Poo"s && t1_res[0].second == "Bob,Bubble,Fluffy"s); assert(t1_res[1].first == "John Doe"s && t1_res[1].second == "Kitty,Spotty"s); assert(t1_res[2].first == "Sam Doe"s && t1_res[2].second == "Sparky"s); auto t2_res = from(t1_data)->group_join(t2_data, [](auto &&i) { return i.Id; }, [](auto &&i) { return i.OwnerId; }, [](auto &&key, auto &&values) { return std::make_pair(key.FirstName + " "s + key.LastName, from(values). select([](auto &&i){ return i.NickName; }). order_by(). to_string(",")); } , true)->order_by([](auto &&p) { return p.first; })->to_vector(); assert(t2_res.size() == 6); assert(t2_res[1].second == std::string() && t2_res[3].second == std::string() && t2_res[5].second == std::string()); //auto of_type() const noexcept -> decltype(auto) struct base { virtual ~base(){} }; struct derived : public base { virtual ~derived(){} }; struct derived2 : public base { virtual ~derived2(){} }; std::list<base*> t1_data = {new derived(), new derived2(), new derived(), new derived(), new derived2()}; auto t1_res = from(t1_data)->of_type<derived2*>(); assert(t1_res->all([](auto &&i){ return typeid(i) == typeid(derived2*); })); assert(t1_res->count() == 2); for(auto &&i : t1_data){ delete i; }; Source: https://habr.com/ru/post/303538/
All Articles