Skip to content

Commit ae1d3a8

Browse files
committed
Stream beta implementation
1 parent daf321b commit ae1d3a8

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ add_executable(unittesting include/stream.h
5656
include/traits.h
5757
include/value_holder.h
5858
include/continuation.h
59+
include/operations.h
5960
include/detail/stream_base.h
6061
include/detail/traits_impl.h
6162
include/detail/stream_impl.h

include/continuation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55

66
namespace stream
77
{
8-
using detail::Continuation;
9-
108
template<bool MakesFinite, typename F>
11-
Continuation<F, MakesFinite> makeContinuation(F &&f)
9+
detail::Continuation<F, MakesFinite> makeContinuation(F &&f)
1210
{
1311
return {::std::forward<F>(f)};
14-
};
12+
}
1513
}
1614

1715
#endif //CPP_STREAM_CONTINUATION_H

include/detail/stream_base.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88

99
namespace stream
1010
{
11+
template<typename, typename>
12+
struct Stream;
13+
14+
1115
namespace detail
1216
{
17+
template<typename OldStream, typename Contin>
18+
struct CombinedStreamTag;
19+
20+
1321
template<typename T, bool Finiteness, typename Derived>
1422
struct StreamBase
1523
{
@@ -22,6 +30,33 @@ namespace stream
2230
static_assert(IsFinite, "This Stream is infinite");
2331
return static_cast<const Derived*>(this)->isEndImpl();
2432
}
33+
34+
35+
template<typename Contin, ::std::enable_if_t<IsContinuationForV<Contin, Derived>>* = nullptr>
36+
auto operator|(Contin &&contin)
37+
{
38+
using V = UnwrapValueHolderT<typename ContinuationForTraits<Contin, Derived>::ValueType>;
39+
using RetStreamT = stream::Stream<V, CombinedStreamTag<Derived, ::std::remove_reference_t<Contin>>>;
40+
41+
return RetStreamT(::std::move(static_cast<Derived&>(*this)), ::std::forward<Contin>(contin));
42+
}
43+
44+
45+
template<typename Factory, ::std::enable_if_t<!IsContinuationForV<Factory, Derived>
46+
&& IsContinuationsFactoryForV<Factory, Derived>>* = nullptr>
47+
auto operator|(Factory &&factory)
48+
{
49+
return operator|(::std::forward<Factory>(factory).template createContinuation<Derived>());
50+
}
51+
52+
53+
template<typename Consumer, ::std::enable_if_t< !IsContinuationForV<Consumer, Derived>
54+
&& !IsContinuationsFactoryForV<Consumer, Derived>
55+
&& IsConsumerForV<Consumer, Derived> >* = nullptr>
56+
decltype(auto) operator|(Consumer &&consumer)
57+
{
58+
return ::std::forward<Consumer>(consumer)(::std::move(static_cast<Derived&>(*this)));
59+
}
2560
};
2661
}
2762
}

include/detail/stream_impl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,18 @@ namespace stream
204204

205205

206206
// Combined
207+
template<typename OldStream, typename Contin>
208+
struct CombinedStreamTag;
209+
207210
template<typename OldStream, typename F, bool ManagesFiniteness>
208-
struct CombinedStreamTag {};
211+
struct CombinedStreamTag<OldStream, Continuation<F, ManagesFiniteness>>
212+
{};
209213

210214
#define CS_PARENT StreamBase<T, StreamTraits<OldStream>::IsFinite | ManagesFiniteness, Derived>
211215

212216
template<typename T, typename F, bool ManagesFiniteness, typename Derived, typename OldStream>
213217
class StreamImpl<T,
214-
CombinedStreamTag<OldStream, F, ManagesFiniteness>,
218+
CombinedStreamTag<OldStream, Continuation<F, ManagesFiniteness>>,
215219
Derived,
216220
void
217221
> : public CS_PARENT

include/detail/traits_impl.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,26 @@ namespace stream
243243
static constexpr bool IsContinuationForV = ContinuationForTraits<C, Stream>::IsContinuation;
244244
// ============================================================================================================
245245

246+
// ============================================================================================================
247+
template<typename Factory, typename Stream, typename = void>
248+
struct ContinuationsFactoryForTraits
249+
{
250+
static constexpr bool IsFactory = false;
251+
};
252+
253+
template<typename Factory, typename Stream>
254+
struct ContinuationsFactoryForTraits<Factory,
255+
Stream,
256+
VoidT<::std::enable_if_t<IsContinuationForV<decltype(::std::declval<Factory>().template createContinuation<Stream>()), Stream>>>
257+
>
258+
{
259+
static constexpr bool IsFactory = true;
260+
};
261+
262+
template<typename Factory, typename Stream>
263+
static constexpr bool IsContinuationsFactoryForV = ContinuationsFactoryForTraits<Factory, Stream>::IsFactory;
264+
// ============================================================================================================
265+
246266
// ============================================================================================================
247267
template<typename T>
248268
struct UnwrapValueHolder
@@ -253,6 +273,9 @@ namespace stream
253273
template<typename T>
254274
struct UnwrapValueHolder<ValueHolder<T>> : UnwrapValueHolder<T>
255275
{};
276+
277+
template<typename T>
278+
using UnwrapValueHolderT = typename UnwrapValueHolder<T>::Type;
256279
// ============================================================================================================
257280
};
258281
}

include/operations.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef CPP_STREAM_OPERATIONS_H
2+
#define CPP_STREAM_OPERATIONS_H
3+
4+
#include "stream.h"
5+
#include "traits.h"
6+
7+
namespace stream
8+
{
9+
namespace ops
10+
{
11+
12+
}
13+
}
14+
15+
#endif //CPP_STREAM_OPERATIONS_H

0 commit comments

Comments
 (0)