xtd 0.2.0
Loading...
Searching...
No Matches
enumerable_count_by.cpp

Shows how to use xtd::linq::enumerable::count_by method.

#include <xtd/xtd>
struct student : iequatable<student> {
student() = default;
student(const string& name, const string& score) : name {name}, score {score} {}
string name;
string score;
bool equals(const student& other) const noexcept override {
return name == other.name && score == other.score;
}
};
auto main() -> int {
auto students = array<student> {
{"Alice", "A"},
{"Bob", "B"},
{"Charlie", "C"},
{"David", "B"},
{"Eve", "A"}
};
const auto& query = students.count_by<string>([](const auto& student) {return student.score;});
for (const auto& [score, count] : query)
console::write_line("Students with a {}-score: {}", score, count);
}
// This code produces the following output :
//
// Students with a A-score: 2
// Students with a B-score: 2
// Students with a C-score: 1
@ query
The xtd::uri::query data.
Definition uri_components.hpp:29