demonstrates how to use xtd::linq::enumerable::count_by method.
#include <xtd/xtd>
struct student {
std::string name;
std::string score;
};
auto main() -> int {
auto students = std::vector<student> {
{"Alice", "A"},
{"Bob", "B"},
{"Charlie", "C"},
{"David", "B"},
{"Eve", "A"}
};
auto query =
from(students).count_by<std::string>([] (
auto&& student) {
return student.score;});
for (const auto& [score, count] : query)
std::println("Students with a {}-score: {}", score, count);
}
auto from(const source_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition from.hpp:28
@ query
The xtd::uri::query data.
Definition uri_components.hpp:29