Skip to content

Commit 73c34f2

Browse files
author
Nikita Provotorov
authored
Merge pull request #4 from NikitkoCent/dev
Release v1.0
2 parents 4e4674e + d0d0a05 commit 73c34f2

22 files changed

+3743
-7
lines changed

CMakeLists.txt

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,26 @@ if (CMAKE_VERSION VERSION_LESS 2.8.11)
5252
endif()
5353
# ================================ GOOGLETEST END =======================================
5454

55-
add_executable(unittesting tests/empty.cpp)
55+
add_executable(unittesting include/stream.h
56+
include/traits.h
57+
include/value_holder.h
58+
include/continuation.h
59+
include/operations.h
60+
include/detail/stream_base.h
61+
include/detail/traits_impl.h
62+
include/detail/stream_impl.h
63+
include/detail/continuation_impl.h
64+
tests/stream_deduction_guides.cpp
65+
tests/filters_int_finite_stream.cpp
66+
tests/filters_int_infinite_stream.cpp
67+
tests/filters_generic_int_stream.cpp
68+
tests/filters_move_only_finite_stream.cpp
69+
tests/filters_move_only_infinite_stream.cpp
70+
tests/filters_generic_move_only_stream.cpp
71+
tests/noisy.h
72+
tests/noisy.cpp
73+
tests/filters_noisy_finite_stream.cpp
74+
tests/filters_generic_noisy_stream.cpp)
5675
target_link_libraries(unittesting gtest gmock_main Threads::Threads)
5776

5877
add_test(NAME do_unittests COMMAND unittesting)
@@ -72,14 +91,19 @@ endif()
7291

7392
MESSAGE("Build type : ${CMAKE_BUILD_TYPE}")
7493
MESSAGE("Used compiler : ${CMAKE_CXX_COMPILER}")
75-
if (CMAKE_BUILD_TYPE EQUAL "Debug")
94+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
7695
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
77-
elseif (CMAKE_BUILD_TYPE EQUAL "Release")
96+
MESSAGE("Linker flags : ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
97+
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
7898
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
79-
elseif (CMAKE_BUILD_TYPE EQUAL "RelWithDebInfo")
99+
MESSAGE("Linker flags : ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
100+
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
80101
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
81-
elseif (CMAKE_BUILD_TYPE EQUAL "MinSizeRel")
102+
MESSAGE("Linker flags : ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
103+
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
82104
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}")
105+
MESSAGE("Linker flags : ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
83106
else()
84107
MESSAGE("Compiler flags : ${CMAKE_CXX_FLAGS}")
108+
MESSAGE("Linker flags : ${CMAKE_EXE_LINKER_FLAGS}")
85109
endif()

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/stream_base.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef CPP_STREAM_DETAIL_STREAM_BASE_H
2+
#define CPP_STREAM_DETAIL_STREAM_BASE_H
3+
4+
#include "traits_impl.h"
5+
#include <type_traits> // ::std::enable_if_t
6+
#include <optional> // ::std::optional
7+
#include "../value_holder.h"
8+
9+
namespace stream
10+
{
11+
template<typename, typename>
12+
struct Stream;
13+
14+
15+
namespace detail
16+
{
17+
template<typename OldStream, typename Contin>
18+
struct CombinedStreamTag;
19+
20+
21+
template<typename T, bool Finiteness, typename Derived>
22+
struct StreamBase
23+
{
24+
using ValueType = RemoveCVRefT<T>;
25+
static constexpr bool IsFinite = Finiteness;
26+
27+
28+
bool isEnd() const
29+
{
30+
static_assert(IsFinite, "This Stream is infinite");
31+
return static_cast<const Derived*>(this)->isEndImpl();
32+
}
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+
}
60+
};
61+
}
62+
}
63+
64+
#endif //CPP_STREAM_DETAIL_STREAM_BASE_H

0 commit comments

Comments
 (0)