Skip to content

Commit 56e71a6

Browse files
committed
DONE!!!!!
1 parent 684055a commit 56e71a6

12 files changed

+37
-32
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ add_executable(unittesting include/stream.h
6565
tests/filters_int_finite_stream.cpp
6666
tests/filters_int_infinite_stream.cpp
6767
tests/filters_generic_int_stream.cpp
68-
#[[tests/filters_move_only_finite_stream.cpp
68+
tests/filters_move_only_finite_stream.cpp
6969
tests/filters_move_only_infinite_stream.cpp
7070
tests/filters_generic_move_only_stream.cpp
7171
tests/noisy.h
7272
tests/noisy.cpp
7373
tests/filters_noisy_finite_stream.cpp
74-
tests/filters_generic_noisy_stream.cpp]])
74+
tests/filters_generic_noisy_stream.cpp)
7575
target_link_libraries(unittesting gtest gmock_main Threads::Threads)
7676

7777
add_test(NAME do_unittests COMMAND unittesting)

include/detail/stream_impl.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ namespace stream
3131
typename StreamBase<T, true, Derived>::ValueType&>>;
3232

3333
StreamImpl()
34-
: it(container.begin())
3534
{}
3635

3736
StreamImpl(Container &&container)
38-
: container(::std::move(container)), it(this->container.begin())
37+
: container(::std::move(container))
3938
{}
4039

4140
StreamImpl(::std::initializer_list<T> initList)
42-
: container(initList), it(container.begin())
41+
: container(initList)
4342
{}
4443

4544
template<typename Arg1, typename... Args>
4645
StreamImpl(Arg1 &&arg1, Args&&... args)
4746
{
4847
initialize(::std::forward<Arg1>(arg1), ::std::forward<Args>(args)...);
49-
it = container.begin();
5048
}
5149

5250

@@ -63,12 +61,19 @@ namespace stream
6361
protected:
6462
bool isEndImpl() const
6563
{
64+
if (!iteratorInitialized)
65+
{
66+
iteratorInitialized = true;
67+
it = container.begin();
68+
}
69+
6670
return (it == container.end());
6771
}
6872

6973
private:
70-
Container container;
71-
typename ContainerTraits<Container>::Iterator it;
74+
mutable Container container;
75+
mutable typename ContainerTraits<Container>::Iterator it;
76+
mutable bool iteratorInitialized = false;
7277

7378

7479
template<typename Arg1>

include/operations.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ namespace stream
5858
template<typename Transform>
5959
auto map(Transform &&transform)
6060
{
61-
return makeContinuation<false>([transform = ::std::forward<Transform>(transform)](auto &&value, auto &&stream) mutable {
62-
using ReturnType = detail::InvokeResultT<::std::decay_t<Transform>, decltype(::std::move(value.get()))>;
61+
return makeContinuation<false>([transform = ::std::forward<Transform>(transform)](auto &&value, auto &&) mutable {
62+
using ReturnType = ::std::invoke_result_t<decltype(transform), decltype(::std::move(value.get()))>;
6363
using Type = ValueHolder<ReturnType>;
6464

6565
return ::std::optional<Type>{transform(::std::move(value.get()))};
@@ -87,8 +87,7 @@ namespace stream
8787
template<typename Identity, typename Accumulator>
8888
auto reduce(Identity &&identity, Accumulator &&accumulator)
8989
{
90-
return [f1 = ::std::forward<Identity>(identity), fn = ::std::forward<Accumulator>(accumulator)](
91-
auto &&stream) mutable {
90+
return [f1 = ::std::forward<Identity>(identity), fn = ::std::forward<Accumulator>(accumulator)](auto &&stream) mutable {
9291
using Type = detail::InvokeResultT<decltype(f1), decltype(::std::move(stream.getNext()->get()))>;
9392

9493
if (stream.isEnd())
@@ -238,7 +237,7 @@ namespace stream
238237
using Type = typename StreamTraits<Stream>::ValueType;
239238

240239
::std::size_t n = this->n;
241-
return makeContinuation<false>([n, vec = ::std::vector<Type>{}](auto &&value, auto &&stream) mutable {
240+
return makeContinuation<false>([n, vec = ::std::vector<Type>{}](auto &&value, auto &&) mutable {
242241
vec.emplace_back(::std::move(value.get()));
243242

244243
if (vec.size() == n)

tests/filters_generic_int_stream.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#include <stream.h>
2-
#include <filters_lib.h>
2+
#include <operations.h>
33
#include <list>
44
#include <vector>
55
#include <string>
66
#include <numeric>
77
#include <functional>
8+
#include <iostream>
89
#include <gtest/gtest.h>
910
#include <gmock/gmock.h>
1011

1112

1213
using stream::Stream;
13-
using namespace stream::filters;
14+
using namespace stream::ops;
1415

1516

1617
TEST(FILTERS_GENERIC_INT_STREAM, REF_CONTAINER)

tests/filters_generic_move_only_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stream.h>
2-
#include <filters_lib.h>
2+
#include <operations.h>
33
#include <list>
44
#include <vector>
55
#include <string>
@@ -11,7 +11,7 @@
1111

1212

1313
using stream::Stream;
14-
using namespace stream::filters;
14+
using namespace stream::ops;
1515

1616

1717
TEST(FILTERS_GENERIC_MOVE_ONLY_STREAM, CONTAINER)

tests/filters_generic_noisy_stream.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "noisy.h"
22
#include <stream.h>
3-
#include <filters_lib.h>
3+
#include <operations.h>
44
#include <list>
55
#include <vector>
66
#include <string>
@@ -11,7 +11,7 @@
1111

1212

1313
using stream::Stream;
14-
using namespace stream::filters;
14+
using namespace stream::ops;
1515

1616

1717
TEST(FILTERS_GENERIC_NOISY_STREAM, REF_CONTAINER)
@@ -27,7 +27,7 @@ TEST(FILTERS_GENERIC_NOISY_STREAM, REF_CONTAINER)
2727

2828
auto result = Stream(list)
2929
| filter([](auto &&v){ return v.value > 2; })
30-
| map([](auto &&v){ v.value = v.value * v.value; return std::move(v); })
30+
| map([](auto &&v){ return Noisy(v.value * v.value); })
3131
| map([](auto &&v){ ++v.value; return std::move(v); })
3232
| filter([](auto &&v) { return v.value > 25; })
3333
| to_vector();
@@ -128,7 +128,7 @@ TEST(FILTERS_GENERIC_NOISY_STREAM, RANGE)
128128
| filter([](auto &&v) { return v.value > 25; })
129129
| to_vector();
130130

131-
ASSERT_EQ(Noisy::copyCount, 0);
131+
ASSERT_EQ(Noisy::copyCount, 10); // because Range consists of InputIterators
132132

133133
ASSERT_EQ(result.size(), 6U);
134134
ASSERT_EQ(result[0].value, 26);

tests/filters_int_finite_stream.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST(FILTERS_INT_FINITE_STREAM, PRINT_TO_GENERIC)
5050
stream::Stream(1, 2, 3, 4, 5, 6, 7, 8, 9) | print_to(stream);
5151
ASSERT_EQ(stream.str(), "1 2 3 4 5 6 7 8 9");
5252
}
53-
/*
53+
5454

5555

5656
TEST(FILTERS_INT_FINITE_STREAM, SKIP_0)
@@ -87,6 +87,7 @@ TEST(FILTERS_INT_FINITE_STREAM, MAP_EMPTY)
8787
ASSERT_TRUE((stream::Stream<int>() | map([](auto &&v){ return std::move(v); }) | to_vector()).empty());
8888
}
8989

90+
9091
TEST(FILTERS_INT_FINITE_STREAM, MAP_1)
9192
{
9293
ASSERT_THAT((stream::Stream(15) | map([](auto &&v){ return v * v; }) | to_vector()), testing::ElementsAre(225));
@@ -99,6 +100,7 @@ TEST(FILTERS_INT_FINITE_STREAM, MAP_GENERIC)
99100
}
100101

101102

103+
102104
TEST(FILTERS_INT_FINITE_STREAM, GET_0_EMPTY)
103105
{
104106
ASSERT_TRUE((stream::Stream<int>() | get(0) | to_vector()).empty());
@@ -352,4 +354,3 @@ TEST(FILTERS_INT_FINITE_STREAM, GROUP_GENERIC_TO_ONE_MORE2)
352354
ASSERT_EQ(result.size(), 1U);
353355
ASSERT_THAT(result[0], testing::ElementsAre(1, 2, 3, 4, 5, 6, 7, 8, 9));
354356
}
355-
*/

tests/filters_int_infinite_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stream.h>
2-
#include <filters_lib.h>
2+
#include <operations.h>
33
#include <gtest/gtest.h>
44
#include <gmock/gmock.h>
55

@@ -19,7 +19,7 @@ namespace
1919

2020

2121
using namespace stream;
22-
using namespace stream::filters;
22+
using namespace stream::ops;
2323

2424

2525
TEST(FILTERS_INT_INFINITE_STREAM, GET_0)

tests/filters_move_only_finite_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stream.h>
2-
#include <filters_lib.h>
2+
#include <operations.h>
33
#include <vector>
44
#include <sstream>
55
#include <type_traits>
@@ -9,7 +9,7 @@
99

1010

1111
using namespace stream;
12-
using namespace stream::filters;
12+
using namespace stream::ops;
1313

1414

1515
TEST(FILTERS_MOVE_ONLY_FINITE_STREAM, SKIP_0)

tests/filters_move_only_infinite_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stream.h>
2-
#include <filters_lib.h>
2+
#include <operations.h>
33
#include <vector>
44
#include <gtest/gtest.h>
55
#include <gmock/gmock.h>
@@ -20,7 +20,7 @@ namespace
2020

2121

2222
using namespace stream;
23-
using namespace stream::filters;
23+
using namespace stream::ops;
2424

2525

2626
TEST(FILTERS_MOVE_ONLY_INFINITE_STREAM, GET_0)

0 commit comments

Comments
 (0)