Skip to content

Commit 6c49bf2

Browse files
Document limitation
1 parent 323fcb2 commit 6c49bf2

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

README.md

Lines changed: 6 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 STL algorithms in some cases. Eg:
14+
* Integrates well with STD algorithms in some cases. Eg:
1515
* `std::move(ch.begin(), ch.end(), ...)`
1616
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
17+
* [See limitations](#known-limitations)
1718
* Tested with GCC, Clang, and MSVC.
1819
* Includes stack-based, exception-free alternative (static channel).
1920

@@ -136,6 +137,10 @@ int main() {
136137

137138
See [examples](https://github.com/andreiavrammsd/cpp-channel/tree/master/examples) and [documentation](https://andreiavrammsd.github.io/cpp-channel/).
138139

140+
## Known limitations
141+
142+
* Integration with some STD algorithms does not compile with MSVC
143+
139144
<br>
140145

141146
Developed with [CLion](https://www.jetbrains.com/?from=serializer) and [Visual Studio Code](https://code.visualstudio.com/).

examples/merge_channels.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,40 @@ int main()
3737
};
3838

3939
const auto transformer = [&input_chan, &output_chan]() {
40-
std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan),
41-
[](int value) { return value * 2; });
40+
const auto double_value = [](int value) { return value * 2; };
41+
42+
#ifdef _MSC_VER
43+
for (auto&& value : input_chan) {
44+
output_chan.write(double_value(value));
45+
}
46+
47+
// Does not work with std::transform:
48+
//
49+
// could be 'void std::queue<T,std::deque<T,std::allocator<int>>>::push(int &&)'
50+
// with
51+
// [
52+
// T=ChannelTest_Traits_Test::TestBody::type
53+
// ]
54+
// D:\a\cpp-channel\cpp-channel\include\msd\channel.hpp(105,20):
55+
// 'void std::queue<T,std::deque<T,std::allocator<int>>>::push(int &&)': cannot convert argument 1 from
56+
// '_OutIt' to 'int &&' with
57+
// [
58+
// T=ChannelTest_Traits_Test::TestBody::type
59+
// ]
60+
// and
61+
// [
62+
// _OutIt=msd::blocking_writer_iterator<msd::channel<ChannelTest_Traits_Test::TestBody::type>>
63+
// ]
64+
// D:\a\cpp-channel\cpp-channel\include\msd\channel.hpp(105,43):
65+
// Reason: cannot convert from '_OutIt' to 'int'
66+
// with
67+
// [
68+
// _OutIt=msd::blocking_writer_iterator<msd::channel<ChannelTest_Traits_Test::TestBody::type>>
69+
// ]
70+
#else
71+
std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan), double_value);
72+
#endif // _MSC_VER
73+
4274
output_chan.close();
4375
};
4476

tests/channel_test.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,40 @@ TEST(ChannelTest, Transform)
379379

380380
// Transform input channel values from MovableOnly to int by multiplying by 2 and write to output channel
381381
const auto double_transformer = [&input_chan, &output_chan]() {
382-
std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan),
383-
[](auto&& value) -> int { return value.getValue() * 2; });
382+
const auto double_value = [](auto&& value) -> int { return value.getValue() * 2; };
383+
384+
#ifdef _MSC_VER
385+
for (auto&& value : input_chan) {
386+
output_chan.write(double_value(value));
387+
}
388+
389+
// Does not work with std::transform:
390+
//
391+
// could be 'void std::queue<T,std::deque<T,std::allocator<int>>>::push(int &&)'
392+
// with
393+
// [
394+
// T=ChannelTest_Traits_Test::TestBody::type
395+
// ]
396+
// D:\a\cpp-channel\cpp-channel\include\msd\channel.hpp(105,20):
397+
// 'void std::queue<T,std::deque<T,std::allocator<int>>>::push(int &&)': cannot convert argument 1 from
398+
// '_OutIt' to 'int &&' with
399+
// [
400+
// T=ChannelTest_Traits_Test::TestBody::type
401+
// ]
402+
// and
403+
// [
404+
// _OutIt=msd::blocking_writer_iterator<msd::channel<ChannelTest_Traits_Test::TestBody::type>>
405+
// ]
406+
// D:\a\cpp-channel\cpp-channel\include\msd\channel.hpp(105,43):
407+
// Reason: cannot convert from '_OutIt' to 'int'
408+
// with
409+
// [
410+
// _OutIt=msd::blocking_writer_iterator<msd::channel<ChannelTest_Traits_Test::TestBody::type>>
411+
// ]
412+
#else
413+
std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan), double_value);
414+
#endif // _MSC_VER
415+
384416
output_chan.close();
385417
};
386418

0 commit comments

Comments
 (0)