Skip to content

Commit d0d0a05

Browse files
author
Nikita Provotorov
authored
Merge pull request #3 from NikitkoCent/remake
Remake
2 parents fd71f36 + 56e71a6 commit d0d0a05

28 files changed

+670
-507
lines changed

CMakeLists.txt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,15 @@ if (CMAKE_VERSION VERSION_LESS 2.8.11)
5252
endif()
5353
# ================================ GOOGLETEST END =======================================
5454

55-
add_executable(unittesting include/traits.h
56-
include/stream.h
57-
include/stream_traits.h
58-
include/filters_lib.h
59-
include/filter.h
60-
include/is_filters_factory_for.h
61-
include/detail/stream_impl.h
62-
include/detail/traits_impl.h
55+
add_executable(unittesting include/stream.h
56+
include/traits.h
57+
include/value_holder.h
58+
include/continuation.h
59+
include/operations.h
6360
include/detail/stream_base.h
64-
include/detail/utility.h
65-
include/detail/stream_traits_impl.h
66-
include/detail/stream_filter_impl.h
67-
include/detail/filter_impl.h
68-
include/detail/is_filters_factory_for_impl.h
61+
include/detail/traits_impl.h
62+
include/detail/stream_impl.h
63+
include/detail/continuation_impl.h
6964
tests/stream_deduction_guides.cpp
7065
tests/filters_int_finite_stream.cpp
7166
tests/filters_int_infinite_stream.cpp

include/continuation.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef CPP_STREAM_CONTINUATION_H
2+
#define CPP_STREAM_CONTINUATION_H
3+
4+
#include "detail/continuation_impl.h"
5+
6+
namespace stream
7+
{
8+
template<bool MakesFinite, typename F>
9+
detail::Continuation<F, MakesFinite> makeContinuation(F &&f)
10+
{
11+
return {::std::forward<F>(f)};
12+
}
13+
}
14+
15+
#endif //CPP_STREAM_CONTINUATION_H

include/detail/continuation_impl.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef CPP_STREAM_DETAIL_CONTINUATION_IMPL_H
2+
#define CPP_STREAM_DETAIL_CONTINUATION_IMPL_H
3+
4+
#include <type_traits> // ::std::decay_t
5+
#include <utility> // ::std::move, ::std::forward
6+
7+
namespace stream
8+
{
9+
namespace detail
10+
{
11+
template<typename C, bool ManagesFiniteness>
12+
class Continuation
13+
{
14+
public:
15+
template<typename F>
16+
Continuation(F &&continuation)
17+
: continuation(::std::forward<F>(continuation))
18+
{}
19+
20+
template<typename V, typename S, bool Fin = ManagesFiniteness,
21+
::std::enable_if_t<Fin>* = nullptr>
22+
decltype(auto) operator()(V &&value, const S& stream, bool &end)
23+
{
24+
return continuation(::std::forward<V>(value), stream, end);
25+
}
26+
27+
template<typename V, typename S, bool Fin = ManagesFiniteness,
28+
::std::enable_if_t<!Fin>* = nullptr>
29+
decltype(auto) operator()(V &&value, const S& stream)
30+
{
31+
return continuation(::std::forward<V>(value), stream);
32+
}
33+
34+
private:
35+
::std::decay_t<C> continuation;
36+
};
37+
}
38+
}
39+
40+
#endif //CPP_STREAM_DETAIL_CONTINUATION_IMPL_H

include/detail/filter_impl.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

include/detail/is_filters_factory_for_impl.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

include/detail/stream_base.h

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,61 @@
11
#ifndef CPP_STREAM_DETAIL_STREAM_BASE_H
22
#define CPP_STREAM_DETAIL_STREAM_BASE_H
33

4-
#include "traits_impl.h" // InvokeResultT
5-
#include "stream_traits_impl.h" // IsStreamFilterFor
6-
#include "is_filters_factory_for_impl.h" // IsFiltersFactoryFor
7-
#include <type_traits> // ::std::enable_if_t, ::std::decay_t, ::std::is_reference
8-
#include <utility> // ::std::move, ::std::forward
4+
#include "traits_impl.h"
5+
#include <type_traits> // ::std::enable_if_t
6+
#include <optional> // ::std::optional
7+
#include "../value_holder.h"
98

109
namespace stream
1110
{
1211
template<typename, typename>
1312
struct Stream;
1413

14+
1515
namespace detail
1616
{
17-
template<typename, typename, typename>
18-
class StreamFilter;
17+
template<typename OldStream, typename Contin>
18+
struct CombinedStreamTag;
1919

2020

21-
template<typename T, bool Finiteness, typename StreamImpl>
22-
class StreamBase
21+
template<typename T, bool Finiteness, typename Derived>
22+
struct StreamBase
2323
{
24-
public:
25-
using Type = ::std::conditional_t<::std::is_reference<T>::value,
26-
::std::reference_wrapper<::std::remove_reference_t<T>>,
27-
T>;
24+
using ValueType = RemoveCVRefT<T>;
2825
static constexpr bool IsFinite = Finiteness;
2926

3027

31-
template<typename Filter, typename ::std::enable_if_t<IsStreamFilterFor<Filter, StreamImpl>::value>* = nullptr>
32-
auto operator|(Filter &&filter)
28+
bool isEnd() const
3329
{
34-
using V = typename InvokeResultT<::std::decay_t<Filter>, Type&&, const StreamImpl&, bool&>::value_type;
35-
return stream::Stream<V, StreamFilter<StreamImpl, Filter, void>>(::std::move(static_cast<StreamImpl&>(*this)),
36-
::std::forward<Filter>(filter));
30+
static_assert(IsFinite, "This Stream is infinite");
31+
return static_cast<const Derived*>(this)->isEndImpl();
3732
}
3833

3934

40-
template<typename Factory, typename ::std::enable_if_t<!IsStreamFilterFor<Factory, StreamImpl>::value
41-
&& IsFiltersFactoryFor<Factory, StreamImpl>::value>* = nullptr>
42-
auto operator|(Factory &&factory)
35+
template<typename Contin, ::std::enable_if_t<IsContinuationForV<Contin, Derived>>* = nullptr>
36+
auto operator|(Contin &&contin)
4337
{
44-
return operator|(::std::forward<Factory>(factory).template createFilter<StreamImpl>());
45-
};
38+
using V = UnwrapValueHolderT<typename ContinuationForTraits<Contin, Derived>::ValueType>;
39+
using RetStreamT = stream::Stream<V, CombinedStreamTag<Derived, ::std::remove_reference_t<Contin>>>;
4640

41+
return RetStreamT(::std::move(static_cast<Derived&>(*this)), ::std::forward<Contin>(contin));
42+
}
4743

48-
template<typename Term, typename ::std::enable_if_t<!IsStreamFilterFor<Term, StreamImpl>::value
49-
&& !IsFiltersFactoryFor<Term, StreamImpl>::value>* = nullptr>
50-
decltype(auto) operator|(Term &&nonFilter)
44+
45+
template<typename Factory, ::std::enable_if_t<!IsContinuationForV<Factory, Derived>
46+
&& IsContinuationsFactoryForV<Factory, Derived>>* = nullptr>
47+
auto operator|(Factory &&factory)
5148
{
52-
return ::std::forward<Term>(nonFilter)(::std::move(static_cast<StreamImpl&>(*this)));
49+
return operator|(::std::forward<Factory>(factory).template createContinuation<Derived>());
5350
}
5451

5552

56-
bool isEnd() const
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)
5757
{
58-
static_assert(IsFinite, "This stream is infinite");
59-
return static_cast<const StreamImpl *>(this)->isEndImpl();
58+
return ::std::forward<Consumer>(consumer)(::std::move(static_cast<Derived&>(*this)));
6059
}
6160
};
6261
}

include/detail/stream_filter_impl.h

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)