Skip to content

Commit 9a4ebda

Browse files
committed
Replace all uses of details::do_while() with internal _do_while()
1 parent f301d1d commit 9a4ebda

File tree

5 files changed

+28
-36
lines changed

5 files changed

+28
-36
lines changed

Release/include/cpprest/astreambuf.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424

2525
namespace Concurrency
2626
{
27+
namespace details
28+
{
29+
template<bool B=true>
30+
task<bool> _do_while(std::function<task<bool>(void)> func)
31+
{
32+
task<bool> first = func();
33+
return first.then([=](bool guard) -> task<bool> {
34+
if (guard)
35+
return Concurrency::details::_do_while<B>(func);
36+
else
37+
return first;
38+
});
39+
}
40+
}
41+
2742
/// Library for asynchronous streams.
2843
namespace streams
2944
{

Release/include/cpprest/streams.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ namespace Concurrency { namespace streams
801801
return true;
802802
};
803803

804-
auto loop = pplx::details::do_while([=]() mutable -> pplx::task<bool>
804+
auto loop = Concurrency::details::_do_while([=]() mutable -> pplx::task<bool>
805805
{
806806
while (buffer.in_avail() > 0)
807807
{
@@ -892,7 +892,7 @@ namespace Concurrency { namespace streams
892892
return pplx::task_from_result(false);
893893
};
894894

895-
auto loop = pplx::details::do_while([=]() mutable -> pplx::task<bool>
895+
auto loop = Concurrency::details::_do_while([=]() mutable -> pplx::task<bool>
896896
{
897897
while ( buffer.in_avail() > 0 )
898898
{
@@ -975,7 +975,7 @@ namespace Concurrency { namespace streams
975975
});
976976
};
977977

978-
auto loop = pplx::details::do_while(copy_to_target);
978+
auto loop = Concurrency::details::_do_while(copy_to_target);
979979

980980
return loop.then([=](bool) mutable -> size_t
981981
{
@@ -1149,7 +1149,7 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
11491149
return false;
11501150
};
11511151

1152-
auto loop = pplx::details::do_while([=]() mutable -> pplx::task<bool>
1152+
auto loop = Concurrency::details::_do_while([=]() mutable -> pplx::task<bool>
11531153
{
11541154
while (buffer.in_avail() > 0)
11551155
{
@@ -1224,7 +1224,7 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
12241224
return _skip_whitespace(buffer).then([=](pplx::task<void> op) -> pplx::task<ReturnType>
12251225
{
12261226
op.wait();
1227-
return pplx::details::do_while(peek_char).then(finish);
1227+
return Concurrency::details::_do_while(peek_char).then(finish);
12281228
});
12291229
}
12301230

Release/include/pplx/pplxtasks.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7345,29 +7345,6 @@ task<_TaskType> task_from_exception(_ExType _Exception, const task_options& _Tas
73457345
return create_task(_Tce, _TaskOptions);
73467346
}
73477347

7348-
namespace details
7349-
{
7350-
/// <summary>
7351-
/// A convenient extension to Concurrency: loop until a condition is no longer met
7352-
/// </summary>
7353-
/// <param name="func">
7354-
/// A function representing the body of the loop. It will be invoked at least once and
7355-
/// then repetitively as long as it returns true.
7356-
/// </param>
7357-
inline
7358-
task<bool> do_while(std::function<task<bool>(void)> func)
7359-
{
7360-
task<bool> first = func();
7361-
return first.then([=](bool guard) -> task<bool> {
7362-
if (guard)
7363-
return do_while(func);
7364-
else
7365-
return first;
7366-
});
7367-
}
7368-
7369-
} // namespace details
7370-
73717348
} // namespace Concurrency
73727349

73737350
#pragma pop_macro("new")

Release/tests/functional/streams/istream_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ TEST(fstream_read_to_end_3)
714714
else
715715
return pplx::task_from_result(false);
716716
};
717-
pplx::details::do_while([=]()-> pplx::task<bool> {
717+
Concurrency::details::_do_while([=]()-> pplx::task<bool> {
718718
return stream.read().then(lambda1);
719719
}).wait();
720720

Release/tests/functional/streams/memstream_tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void streambuf_putc(StreamBufferType& wbuf)
4848
size_t count = 10;
4949
auto seg2 = [&count](typename StreamBufferType::int_type ) { return (--count > 0); };
5050
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putc(s[0]).then(seg2); };
51-
pplx::details::do_while(seg1).wait();
51+
Concurrency::details::_do_while(seg1).wait();
5252

5353
VERIFY_ARE_EQUAL(s.size() + 10, wbuf.in_avail());
5454

@@ -83,7 +83,7 @@ void streambuf_putc(concurrency::streams::rawptr_buffer<CharType>& wbuf)
8383
size_t count = 10;
8484
auto seg2 = [&count](typename StreamBufferType::int_type ) { return (--count > 0); };
8585
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putc(s[0]).then(seg2); };
86-
pplx::details::do_while(seg1).wait();
86+
Concurrency::details::_do_while(seg1).wait();
8787

8888
VERIFY_ARE_EQUAL(s.size() + 10, wbuf.block().size());
8989

@@ -119,7 +119,7 @@ void streambuf_putc(concurrency::streams::container_buffer<CollectionType>& wbuf
119119
size_t count = 10;
120120
auto seg2 = [&count](typename StreamBufferType::int_type ) { return (--count > 0); };
121121
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putc(s[0]).then(seg2); };
122-
pplx::details::do_while(seg1).wait();
122+
Concurrency::details::_do_while(seg1).wait();
123123

124124
VERIFY_ARE_EQUAL(s.size() + 10, wbuf.collection().size());
125125

@@ -150,7 +150,7 @@ void streambuf_putn(StreamBufferType& wbuf)
150150
int count = 10;
151151
auto seg2 = [&count](size_t ) { return (--count > 0); };
152152
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putn_nocopy(s.data(), s.size()).then(seg2); };
153-
pplx::details::do_while(seg1).wait();
153+
Concurrency::details::_do_while(seg1).wait();
154154
VERIFY_ARE_EQUAL(s.size() * 12, wbuf.in_avail());
155155

156156
wbuf.close().get();
@@ -180,7 +180,7 @@ void streambuf_putn(concurrency::streams::rawptr_buffer<CharType>& wbuf)
180180
int count = 10;
181181
auto seg2 = [&count](size_t ) { return (--count > 0); };
182182
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putn_nocopy(s.data(), s.size()).then(seg2); };
183-
pplx::details::do_while(seg1).wait();
183+
Concurrency::details::_do_while(seg1).wait();
184184

185185
wbuf.close().get();
186186
VERIFY_IS_FALSE(wbuf.can_write());
@@ -209,7 +209,7 @@ void streambuf_putn(concurrency::streams::container_buffer<CollectionType>& wbuf
209209
int count = 10;
210210
auto seg2 = [&count](size_t ) { return (--count > 0); };
211211
auto seg1 = [&s,&wbuf, seg2]() { return wbuf.putn_nocopy(s.data(), s.size()).then(seg2); };
212-
pplx::details::do_while(seg1).wait();
212+
Concurrency::details::_do_while(seg1).wait();
213213

214214
wbuf.close().get();
215215
VERIFY_IS_FALSE(wbuf.can_write());
@@ -1935,7 +1935,7 @@ void IStreamTest11()
19351935
auto seg2 = [&ch](int val) { return (val != -1) && (++ch <= 'z'); };
19361936
auto seg1 = [=,&ch,&rbuf]() { return rbuf.putc(ch).then(seg2); };
19371937

1938-
pplx::details::do_while(seg1).wait();
1938+
Concurrency::details::_do_while(seg1).wait();
19391939

19401940
VERIFY_ARE_EQUAL(26u, rbuf.in_avail());
19411941

0 commit comments

Comments
 (0)