xtd 1.0.0
Loading...
Searching...
No Matches
enumerable_count_by2.cpp

Shows 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<string>(_*member(&student::score));
for (const auto& [score, count] : query)
std::println("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
constexpr auto _
The xtd::expressions::_ placeholder instance is used by expression that have only one argument.
Definition args.hpp:66
constexpr auto member(member_t member)
The xtd::expressions::member is use to bind object member.
Definition member_expression.hpp:43
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