@@ -776,60 +776,52 @@ namespace Concurrency { namespace streams
776
776
777
777
std::shared_ptr<_read_helper> _locals = std::make_shared<_read_helper>();
778
778
779
- // We're having to create all these lambdas because VS 2010 has trouble compiling
780
- // nested lambdas.
781
- auto after_putn =
782
- [=](pplx::task<size_t > wrote) mutable -> bool
779
+ auto flush = [=]() mutable
780
+ {
781
+ return target.putn (_locals->outbuf , _locals->write_pos ).then ([=](size_t wrote) mutable
783
782
{
784
- _locals->total += wrote. get () ;
783
+ _locals->total += wrote;
785
784
_locals->write_pos = 0 ;
786
- target.sync (). wait ();
787
- return true ;
788
- };
785
+ return target.sync ();
786
+ }) ;
787
+ };
789
788
790
- auto flush =
791
- [=] () mutable -> pplx::task<bool >
789
+ auto update = [=](int_type ch) mutable -> pplx::task<bool >
792
790
{
793
- return target.putn (_locals->outbuf , _locals->write_pos ).then (after_putn);
794
- };
795
-
796
- auto update = [=] (int_type ch) mutable -> bool
797
- {
798
- if ( ch == ::concurrency::streams::char_traits<CharType>::eof () ) return false ;
799
- if ( ch == delim ) return false ;
791
+ if (ch == ::concurrency::streams::char_traits<CharType>::eof ()) return pplx::task_from_result (false );
792
+ if (ch == delim) return pplx::task_from_result (false );
800
793
801
794
_locals->outbuf [_locals->write_pos ] = static_cast <CharType>(ch);
802
795
_locals->write_pos += 1 ;
803
796
804
- if ( _locals->is_full () )
797
+ if (_locals->is_full ())
805
798
{
806
- return flush ().get ( );
799
+ return flush ().then ([] { return true ; } );
807
800
}
808
801
809
- return true ;
802
+ return pplx::task_from_result ( true ) ;
810
803
};
811
804
812
805
auto loop = pplx::details::do_while ([=]() mutable -> pplx::task<bool >
813
806
{
814
- while ( buffer.in_avail () > 0 )
807
+ while (buffer.in_avail () > 0 )
815
808
{
816
809
int_type ch = buffer.sbumpc ();
817
810
818
- if ( ch == req_async )
811
+ if (ch == req_async)
812
+ {
819
813
break ;
820
-
821
- if ( !update (ch) )
822
- return pplx::task_from_result (false );
823
- }
814
+ }
824
815
816
+ return update (ch);
817
+ }
825
818
return buffer.bumpc ().then (update);
826
819
});
827
820
828
- return loop.then ([=](bool ) mutable -> size_t
829
- {
830
- flush ().wait ();
831
- return _locals->total ;
832
- });
821
+ return loop.then ([=](bool ) mutable
822
+ {
823
+ return flush ().then ([=] { return _locals->total ; });
824
+ });
833
825
}
834
826
835
827
// / <summary>
@@ -851,52 +843,48 @@ namespace Concurrency { namespace streams
851
843
852
844
std::shared_ptr<_read_helper> _locals = std::make_shared<_read_helper>();
853
845
854
- // We're having to create all these lambdas because VS 2010 has trouble compiling
855
- // nested lambdas.
856
- auto after_putn =
857
- [=](pplx::task<size_t > wrote) mutable -> bool
846
+ auto flush = [=]() mutable
847
+ {
848
+ return target.putn (_locals->outbuf , _locals->write_pos ).then ([=](size_t wrote) mutable
858
849
{
859
- _locals->total += wrote. get () ;
850
+ _locals->total += wrote;
860
851
_locals->write_pos = 0 ;
861
- target.sync (). wait ();
862
- return true ;
863
- };
852
+ return target.sync ();
853
+ }) ;
854
+ };
864
855
865
- auto flush =
866
- [=] () mutable -> pplx::task<bool >
856
+ auto update = [=](typename concurrency::streams::char_traits<CharType>::int_type ch) mutable
867
857
{
868
- return target.putn (_locals->outbuf , _locals->write_pos ).then (after_putn);
869
- };
870
-
871
- auto update = [=] (typename concurrency::streams::char_traits<CharType>::int_type ch) mutable -> bool
872
- {
873
- if ( ch == concurrency::streams::char_traits<CharType>::eof () ) return false ;
874
- if ( ch == ' \n ' ) return false ;
875
- if ( ch == ' \r ' ) { _locals->saw_CR = true ; return true ; }
858
+ if (ch == concurrency::streams::char_traits<CharType>::eof ()) return pplx::task_from_result (false );
859
+ if (ch == ' \n ' ) return pplx::task_from_result (false );
860
+ if (ch == ' \r ' )
861
+ {
862
+ _locals->saw_CR = true ;
863
+ return pplx::task_from_result (true );
864
+ }
876
865
877
866
_locals->outbuf [_locals->write_pos ] = static_cast <CharType>(ch);
878
867
_locals->write_pos += 1 ;
879
868
880
- if ( _locals->is_full () )
869
+ if (_locals->is_full ())
881
870
{
882
- return flush ().get ( );
871
+ return flush ().then ([] { return true ; } );
883
872
}
884
873
885
- return true ;
886
- };
887
-
888
- auto return_false =
889
- [](pplx::task<typename concurrency::streams::char_traits<CharType>::int_type>) -> pplx::task<bool >
890
- {
891
- return pplx::task_from_result (false );
874
+ return pplx::task_from_result (true );
892
875
};
893
876
894
- auto update_after_cr =
895
- [=] (typename concurrency::streams::char_traits<CharType>::int_type ch) mutable -> pplx::task<bool >
877
+ auto update_after_cr = [=] (typename concurrency::streams::char_traits<CharType>::int_type ch) mutable -> pplx::task<bool >
896
878
{
897
- if ( ch == concurrency::streams::char_traits<CharType>::eof () ) return pplx::task_from_result (false );
898
- if ( ch == ' \n ' )
899
- return buffer.bumpc ().then (return_false);
879
+ if (ch == concurrency::streams::char_traits<CharType>::eof ()) return pplx::task_from_result (false );
880
+ if (ch == ' \n ' )
881
+ {
882
+ return buffer.bumpc ().then ([](
883
+ #ifndef _MS_WINDOWS // Required by GCC
884
+ typename
885
+ #endif
886
+ concurrency::streams::char_traits<CharType>::int_type) { return false ; });
887
+ }
900
888
901
889
return pplx::task_from_result (false );
902
890
};
@@ -910,35 +898,33 @@ namespace Concurrency { namespace streams
910
898
#endif
911
899
concurrency::streams::char_traits<CharType>::int_type ch;
912
900
913
- if ( _locals->saw_CR )
901
+ if (_locals->saw_CR )
914
902
{
915
903
ch = buffer.sgetc ();
916
- if ( ch == ' \n ' )
904
+ if (ch == ' \n ' )
917
905
buffer.sbumpc ();
918
906
return pplx::task_from_result (false );
919
907
}
920
908
921
909
ch = buffer.sbumpc ();
922
910
923
- if ( ch == req_async )
911
+ if (ch == req_async)
924
912
break ;
925
913
926
- if ( !update (ch) )
927
- return pplx::task_from_result (false );
914
+ return update (ch);
928
915
}
929
916
930
- if ( _locals->saw_CR )
917
+ if (_locals->saw_CR )
931
918
{
932
919
return buffer.getc ().then (update_after_cr);
933
920
}
934
921
return buffer.bumpc ().then (update);
935
922
});
936
923
937
- return loop.then ([=](bool ) mutable -> size_t
938
- {
939
- flush ().wait ();
940
- return _locals->total ;
941
- });
924
+ return loop.then ([=](bool ) mutable
925
+ {
926
+ return flush ().then ([=] { return _locals->total ; });
927
+ });
942
928
}
943
929
944
930
// / <summary>
@@ -1141,30 +1127,30 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
1141
1127
{
1142
1128
int_type req_async = concurrency::streams::char_traits<CharType>::requires_async ();
1143
1129
1144
- auto update = [=] (int_type ch) mutable -> bool
1130
+ auto update = [=] (int_type ch) mutable
1145
1131
{
1146
1132
if (isspace (ch))
1147
1133
{
1148
1134
if (buffer.sbumpc () == req_async)
1149
- buffer.nextc ().wait ();
1150
- return true ;
1135
+ {
1136
+ return buffer.nextc ().then ([](int_type) { return true ; });
1137
+ }
1138
+ return pplx::task_from_result (true );
1151
1139
}
1152
1140
1153
- return false ;
1141
+ return pplx::task_from_result ( false ) ;
1154
1142
};
1155
1143
1156
1144
auto loop = pplx::details::do_while ([=]() mutable -> pplx::task<bool >
1157
1145
{
1158
- while ( buffer.in_avail () > 0 )
1146
+ while (buffer.in_avail () > 0 )
1159
1147
{
1160
1148
int_type ch = buffer.sgetc ();
1161
1149
1162
- if ( ch == req_async )
1150
+ if (ch == req_async)
1163
1151
break ;
1164
1152
1165
- if ( !update (ch) ) {
1166
- return pplx::task_from_result (false );
1167
- }
1153
+ return update (ch);
1168
1154
}
1169
1155
return buffer.getc ().then (update);
1170
1156
});
@@ -1184,8 +1170,6 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1184
1170
{
1185
1171
std::shared_ptr<StateType> state = std::make_shared<StateType>();
1186
1172
1187
- auto update_end = [=] (pplx::task<int_type> op) -> bool { op.wait (); return true ; };
1188
-
1189
1173
auto update = [=] (pplx::task<int_type> op) -> pplx::task<bool >
1190
1174
{
1191
1175
int_type ch = op.get ();
@@ -1195,7 +1179,7 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1195
1179
return pplx::task_from_result (false );
1196
1180
// We peeked earlier, so now we must advance the position.
1197
1181
concurrency::streams::streambuf<CharType> buf = buffer;
1198
- return buf.bumpc ().then (update_end );
1182
+ return buf.bumpc ().then ([](int_type) { return true ; } );
1199
1183
};
1200
1184
1201
1185
auto peek_char = [=]() -> pplx::task<bool >
@@ -1209,7 +1193,7 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1209
1193
while (get_op.is_done ())
1210
1194
{
1211
1195
auto condition = update (get_op);
1212
- if ( !condition.is_done () || !condition.get ())
1196
+ if (!condition.is_done () || !condition.get ())
1213
1197
return condition;
1214
1198
1215
1199
get_op = buf.getc ();
@@ -1229,7 +1213,6 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1229
1213
return _skip_whitespace (buffer).then ([=](pplx::task<void > op) -> pplx::task<ReturnType>
1230
1214
{
1231
1215
op.wait ();
1232
-
1233
1216
return pplx::details::do_while (peek_char).then (finish);
1234
1217
});
1235
1218
}
0 commit comments