Skip to content

Commit 8c23249

Browse files
Document limitation
1 parent 323fcb2 commit 8c23249

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ int main() {
136136

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

139+
## Known limitations
140+
141+
* Integration with some std algorithms does not compile with MSVC
142+
139143
<br>
140144

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

examples/merge_channels.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,42 @@ 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+
74+
std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan), double_value);
75+
4276
output_chan.close();
4377
};
4478

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)