ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
group_by.hpp
1#pragma once
2
3#include <rpp/observables/details/member_overload.hpp>
4#include <rpp/utils/function_traits.hpp>
5
6#include <concepts>
7#include <functional>
8
9
10namespace rpp::details
11{
12struct group_by_tag;
13}
14
15namespace rpp::details
16{
17template<constraint::decayed_type Type,
18 constraint::decayed_type TKey,
19 std::invocable<Type> KeySelector,
20 std::invocable<Type> ValueSelector,
21 std::strict_weak_order<TKey, TKey> KeyComparator>
22auto group_by_impl(auto&& observable, KeySelector&& key_selector, ValueSelector&& value_selector, KeyComparator&& comparator);
23
24template<constraint::decayed_type Type, typename SpecificObservable>
25struct member_overload<Type, SpecificObservable, group_by_tag>
26{
69 template<std::invocable<Type> KeySelector,
70 std::invocable<Type> ValueSelector = std::identity,
71 typename TKey = rpp::utils::decayed_invoke_result_t<KeySelector, Type>,
72 std::strict_weak_order<TKey, TKey> KeyComparator = std::less<TKey>>
73 auto group_by(KeySelector&& key_selector, ValueSelector&& value_selector = {}, KeyComparator&& comparator = {}) const& requires is_header_included<group_by_tag, KeySelector, ValueSelector, TKey, KeyComparator>
74 {
75 return group_by_impl<Type, TKey>(*static_cast<const SpecificObservable*>(this), std::forward<KeySelector>(key_selector), std::forward<ValueSelector>(value_selector), std::forward<KeyComparator>(comparator));
76 }
77
78 template<std::invocable<Type> KeySelector,
79 std::invocable<Type> ValueSelector = std::identity,
80 typename TKey = rpp::utils::decayed_invoke_result_t<KeySelector, Type>,
81 std::strict_weak_order<TKey, TKey> KeyComparator = std::less<TKey>>
82 auto group_by(KeySelector&& key_selector, ValueSelector&& value_selector = {}, KeyComparator&& comparator = {}) && requires is_header_included<group_by_tag, KeySelector, ValueSelector, TKey, KeyComparator>
83 {
84 return group_by_impl<Type, TKey>(std::move(*static_cast<SpecificObservable*>(this)), std::forward<KeySelector>(key_selector), std::forward<ValueSelector>(value_selector), std::forward<KeyComparator>(comparator));
85 }
86};
87} // namespace rpp::details
Definition: member_overload.hpp:19