Skip to content

Commit ca95f04

Browse files
LoopinFooldeanberris
authored andcommitted
Use generic iterator range instead of casting between iterator types. Avoids an issue with Microsoft's checked iterators and is likely more correct/portable. (cpp-netlib#852)
1 parent 38e48c9 commit ca95f04

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

boost/network/protocol/http/client/connection/async_normal.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct chunk_encoding_parser {
5151
size_t chunk_size;
5252
buffer_type buffer;
5353

54-
void update_chunk_size(char_const_range const &range) {
54+
template<typename T>
55+
void update_chunk_size(boost::iterator_range<T> const &range) {
5556
if (range.empty()) return;
5657
std::stringstream ss;
5758
ss << std::hex << range;
@@ -61,7 +62,8 @@ struct chunk_encoding_parser {
6162
chunk_size = (chunk_size << (range.size() * 4)) | size;
6263
}
6364

64-
char_const_range operator()(char_const_range const &range) {
65+
template<typename T>
66+
char_const_range operator()(boost::iterator_range<T> const &range) {
6567
auto iter = boost::begin(range);
6668
auto begin = iter;
6769
auto pos = boost::begin(buffer);
@@ -485,10 +487,8 @@ struct http_async_connection
485487
const auto parse_buffer_size = parse_chunk_encoding.buffer.size();
486488
for (size_t i = 0; i < this->partial_parsed.size(); i += parse_buffer_size) {
487489
auto range = parse_chunk_encoding(boost::make_iterator_range(
488-
static_cast<
489-
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) + i,
490-
static_cast<
491-
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) +
490+
this->partial_parsed.cbegin() + i,
491+
this->partial_parsed.cbegin() +
492492
std::min(i + parse_buffer_size, this->partial_parsed.size())));
493493
body_string.append(boost::begin(range), boost::end(range));
494494
}

0 commit comments

Comments
 (0)