k06a / boolinq

Simplest C++ header-only LINQ template library
MIT License
628 stars 79 forks source link

I don't know how to do this #48

Closed Tomatin closed 2 years ago

Tomatin commented 3 years ago

I really like this implementation, but I don't know how to solve this:

struct Tax {
    std::string name;
    int amount_1;
    int amount_2;
    int amount_3;
};

std::vector<Tax> taxes = {
    {"tax 1", 1, 1},
    {"tax 2", 1, 1},
    {"tax 1", 2, 2},
    {"tax 3", 3, 3},
    {"tax 1", 4, 4},
};

The result that I expect would be a vector with these values, where for each tax.name the corresponding amounts are added

Dump result vector

"tax 1", 7, 7
"tax 2", 1, 1
"tax 3", 3, 3

Thanks in advance !

k06a commented 2 years ago

Hi @Tomatin! Here I provided an example: https://github.com/k06a/boolinq/pull/51/files Hope you can use C++14 to be able to use lambda with auto parameter type.