Skip to content

Commit a699fb3

Browse files
Use std::fill_n
1 parent dad2512 commit a699fb3

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
* Blocking (forever waiting to fetch).
1212
* Range-based for loop supported.
1313
* Close to prevent pushing and stop waiting to fetch.
14-
* Integrates well with STD algorithms in some cases. Eg:
14+
* Integrates with some of the STD algorithms. Eg:
1515
* `std::move(ch.begin(), ch.end(), ...)`
1616
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
17+
* `std::copy(chan.begin(), chan.end(), ...);`
1718
* Tested with GCC, Clang, and MSVC.
1819
* Includes stack-based, exception-free alternative (static channel).
1920

tests/channel_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ TEST(ChannelTest, CopyToVector)
479479

480480
// Producer: write 1..4 into channel and close
481481
const auto producer = [&]() {
482+
std::fill_n(msd::back_inserter(chan), 4, 0);
483+
482484
for (int i = 1; i <= 4; ++i) {
483485
chan.write(i);
484486
}
@@ -490,5 +492,5 @@ TEST(ChannelTest, CopyToVector)
490492
// Copy from channel to vector
491493
std::copy(chan.begin(), chan.end(), std::back_inserter(results));
492494

493-
EXPECT_EQ(results, std::vector<int>({1, 2, 3, 4}));
495+
EXPECT_EQ(results, std::vector<int>({0, 0, 0, 0, 1, 2, 3, 4}));
494496
}

0 commit comments

Comments
 (0)