@@ -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,44 @@ 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 ([](concurrency::streams::char_traits<CharType>::int_type) { return false ; });
883
+ }
900
884
901
885
return pplx::task_from_result (false );
902
886
};
@@ -910,35 +894,33 @@ namespace Concurrency { namespace streams
910
894
#endif
911
895
concurrency::streams::char_traits<CharType>::int_type ch;
912
896
913
- if ( _locals->saw_CR )
897
+ if (_locals->saw_CR )
914
898
{
915
899
ch = buffer.sgetc ();
916
- if ( ch == ' \n ' )
900
+ if (ch == ' \n ' )
917
901
buffer.sbumpc ();
918
902
return pplx::task_from_result (false );
919
903
}
920
904
921
905
ch = buffer.sbumpc ();
922
906
923
- if ( ch == req_async )
907
+ if (ch == req_async)
924
908
break ;
925
909
926
- if ( !update (ch) )
927
- return pplx::task_from_result (false );
910
+ return update (ch);
928
911
}
929
912
930
- if ( _locals->saw_CR )
913
+ if (_locals->saw_CR )
931
914
{
932
915
return buffer.getc ().then (update_after_cr);
933
916
}
934
917
return buffer.bumpc ().then (update);
935
918
});
936
919
937
- return loop.then ([=](bool ) mutable -> size_t
938
- {
939
- flush ().wait ();
940
- return _locals->total ;
941
- });
920
+ return loop.then ([=](bool ) mutable
921
+ {
922
+ return flush ().then ([=] { return _locals->total ; });
923
+ });
942
924
}
943
925
944
926
// / <summary>
@@ -1141,30 +1123,30 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
1141
1123
{
1142
1124
int_type req_async = concurrency::streams::char_traits<CharType>::requires_async ();
1143
1125
1144
- auto update = [=] (int_type ch) mutable -> bool
1126
+ auto update = [=] (int_type ch) mutable
1145
1127
{
1146
1128
if (isspace (ch))
1147
1129
{
1148
1130
if (buffer.sbumpc () == req_async)
1149
- buffer.nextc ().wait ();
1150
- return true ;
1131
+ {
1132
+ return buffer.nextc ().then ([](int_type) { return true ; });
1133
+ }
1134
+ return pplx::task_from_result (true );
1151
1135
}
1152
1136
1153
- return false ;
1137
+ return pplx::task_from_result ( false ) ;
1154
1138
};
1155
1139
1156
1140
auto loop = pplx::details::do_while ([=]() mutable -> pplx::task<bool >
1157
1141
{
1158
- while ( buffer.in_avail () > 0 )
1142
+ while (buffer.in_avail () > 0 )
1159
1143
{
1160
1144
int_type ch = buffer.sgetc ();
1161
1145
1162
- if ( ch == req_async )
1146
+ if (ch == req_async)
1163
1147
break ;
1164
1148
1165
- if ( !update (ch) ) {
1166
- return pplx::task_from_result (false );
1167
- }
1149
+ return update (ch);
1168
1150
}
1169
1151
return buffer.getc ().then (update);
1170
1152
});
@@ -1184,8 +1166,6 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1184
1166
{
1185
1167
std::shared_ptr<StateType> state = std::make_shared<StateType>();
1186
1168
1187
- auto update_end = [=] (pplx::task<int_type> op) -> bool { op.wait (); return true ; };
1188
-
1189
1169
auto update = [=] (pplx::task<int_type> op) -> pplx::task<bool >
1190
1170
{
1191
1171
int_type ch = op.get ();
@@ -1195,7 +1175,7 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1195
1175
return pplx::task_from_result (false );
1196
1176
// We peeked earlier, so now we must advance the position.
1197
1177
concurrency::streams::streambuf<CharType> buf = buffer;
1198
- return buf.bumpc ().then (update_end );
1178
+ return buf.bumpc ().then ([](int_type) { return true ; } );
1199
1179
};
1200
1180
1201
1181
auto peek_char = [=]() -> pplx::task<bool >
@@ -1209,7 +1189,7 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1209
1189
while (get_op.is_done ())
1210
1190
{
1211
1191
auto condition = update (get_op);
1212
- if ( !condition.is_done () || !condition.get ())
1192
+ if (!condition.is_done () || !condition.get ())
1213
1193
return condition;
1214
1194
1215
1195
get_op = buf.getc ();
@@ -1229,7 +1209,6 @@ pplx::task<ReturnType> concurrency::streams::_type_parser_base<CharType>::_parse
1229
1209
return _skip_whitespace (buffer).then ([=](pplx::task<void > op) -> pplx::task<ReturnType>
1230
1210
{
1231
1211
op.wait ();
1232
-
1233
1212
return pplx::details::do_while (peek_char).then (finish);
1234
1213
});
1235
1214
}
0 commit comments