@@ -20,45 +20,18 @@ namespace kangaru {
2020 };
2121 };
2222
23- template <template <typename , typename > typename Branch, kangaru::source Source, typename State>
24- struct rebind_wrapper <Branch<Source, State>> {
25- template <kangaru::source NewSource, typename NewState = State> requires requires { typename Branch<NewSource, NewState>; }
26- struct ttype {
27- using type = Branch<NewSource, NewState>;
28- };
29- };
30-
3123 template <template <typename > typename Branch, kangaru::source Source>
3224 struct rebind_wrapper <Branch<Source> const > {
3325 template <kangaru::source NewSource> requires requires { typename Branch<NewSource>; }
3426 struct ttype {
3527 using type = Branch<NewSource>;
3628 };
3729 };
38-
39- template <template <typename , typename > typename Branch, kangaru::source Source, typename State>
40- struct rebind_wrapper <Branch<Source, State> const > {
41- template <kangaru::source NewSource, typename NewState = State> requires requires { typename Branch<NewSource, NewState>; }
42- struct ttype {
43- using type = Branch<NewSource, NewState>;
44- };
45- };
4630 } // namespace detail::source_helper
4731
4832 template <typename Source>
49- concept weak_rebindable_wrapping_source =
33+ concept transparent_rebindable_wrapping_source =
5034 wrapping_source<Source>
51- and requires {
52- typename std::type_identity_t <
53- typename detail::source_helper::rebind_wrapper<Source>::template ttype<
54- wrapped_source_t <Source>
55- >::type
56- >;
57- };
58-
59- template <typename Source>
60- concept stateless_rebindable_wrapping_source =
61- weak_rebindable_wrapping_source<Source>
6235 and requires (Source source) {
6336 typename std::type_identity_t <
6437 typename detail::source_helper::rebind_wrapper<Source>::template ttype<
@@ -69,34 +42,24 @@ namespace kangaru {
6942 typename detail::source_helper::rebind_wrapper<Source>::template ttype<std::decay_t <decltype (source.source )>>::type,
7043 std::decay_t <decltype (source.source )>
7144 >;
72- };;
45+ };
7346
7447 template <typename Source>
7548 concept stateful_rebindable_wrapping_source =
76- weak_rebindable_wrapping_source <Source>
49+ wrapping_source <Source>
7750 and requires (Source source) {
78- typename std::type_identity_t <
79- typename detail::source_helper::rebind_wrapper<Source>::template ttype<
80- std::decay_t <decltype (source.source )>,
81- decltype (KANGARU5_NO_ADL (ref)(source))
82- >::type
83- >;
84- requires std::constructible_from<
85- typename detail::source_helper::rebind_wrapper<Source>::template ttype<
86- std::decay_t <decltype (source.source )>,
87- decltype (KANGARU5_NO_ADL (ref)(source))
88- >::type,
89- std::decay_t <decltype (source.source )>,
90- decltype (KANGARU5_NO_ADL (ref)(source))
91- >;
51+ Source::rebind (source, none_source{});
9252 };
9353
9454 template <typename Source>
9555 concept rebindable_wrapping_source =
96- stateless_rebindable_wrapping_source <Source>
56+ transparent_rebindable_wrapping_source <Source>
9757 or stateful_rebindable_wrapping_source<Source>;
9858
9959 namespace detail ::source_helper {
60+ // TODO: Design an interface where rebinding might branch off in composed sources
61+ // and allow rebinding with a transformed leaf instead of ignoring it.
62+
10063 // Forward declaration because otherwise the top overloads cannot find the bottom ones.
10164 template <kangaru::source Leaf> requires (not reference_wrapper<Leaf> and not rebindable_wrapping_source<Leaf>)
10265 constexpr auto rebind_source_tree(forwarded_source auto && new_leaf, Leaf&) noexcept ;
@@ -124,15 +87,8 @@ namespace kangaru {
12487 template <rebindable_wrapping_source Wrapper> requires (not reference_wrapper<Wrapper>)
12588 constexpr auto rebind_source_tree(forwarded_source auto && new_leaf, Wrapper& source) noexcept {
12689 if constexpr (stateful_rebindable_wrapping_source<Wrapper>) {
127- using rebound = typename detail::source_helper::rebind_wrapper<Wrapper>::template ttype<
128- decltype (KANGARU5_NO_ADL (rebind_source_tree)(KANGARU5_FWD (new_leaf), source.source )),
129- decltype (KANGARU5_NO_ADL (ref)(source))
130- >::type;
131- return rebound{
132- KANGARU5_NO_ADL (rebind_source_tree)(KANGARU5_FWD (new_leaf), source.source ),
133- KANGARU5_NO_ADL (ref)(source),
134- };
135- } else if constexpr (stateless_rebindable_wrapping_source<Wrapper>) {
90+ return Wrapper::rebind (source, KANGARU5_NO_ADL (rebind_source_tree)(KANGARU5_FWD (new_leaf), source.source ));
91+ } else if constexpr (transparent_rebindable_wrapping_source<Wrapper>) {
13692 using rebound = typename detail::source_helper::rebind_wrapper<Wrapper>::template ttype<
13793 decltype (KANGARU5_NO_ADL (rebind_source_tree)(KANGARU5_FWD (new_leaf), source.source ))
13894 >::type;
@@ -143,16 +99,6 @@ namespace kangaru {
14399 static_assert (not std::same_as<Wrapper, Wrapper>, " exhaustive" );
144100 }
145101 }
146-
147- template <typename Source> requires (forwarded_source<Source> and not wrapping_source<std::remove_reference_t <Source>>)
148- constexpr auto source_tree_leaf(Source&& source) -> auto&& {
149- return KANGARU5_FWD (source);
150- }
151-
152- template <typename Source> requires (wrapping_source<std::remove_reference_t <Source>>)
153- constexpr auto source_tree_leaf(Source&& source) -> auto&& {
154- return KANGARU5_NO_ADL (source_tree_leaf)(KANGARU5_FWD (source).source );
155- }
156102 } // namespace detail::source_helper
157103} // namespace kangaru
158104
0 commit comments