MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / advance

Function advance

3rd/asio-1.24.0/include/asio/buffers_iterator.hpp:407–485  ·  view source on GitHub ↗

Advance the iterator by the specified distance.

Source from the content-addressed store, hash-verified

405
406 // Advance the iterator by the specified distance.
407 void advance(std::ptrdiff_t n)
408 {
409 if (n > 0)
410 {
411 ASIO_ASSERT(current_ != end_ && "iterator out of bounds");
412 for (;;)
413 {
414 std::ptrdiff_t current_buffer_balance
415 = current_buffer_.size() - current_buffer_position_;
416
417 // Check if the advance can be satisfied by the current buffer.
418 if (current_buffer_balance > n)
419 {
420 position_ += n;
421 current_buffer_position_ += n;
422 return;
423 }
424
425 // Update position.
426 n -= current_buffer_balance;
427 position_ += current_buffer_balance;
428
429 // Move to next buffer. If it is empty then it will be skipped on the
430 // next iteration of this loop.
431 if (++current_ == end_)
432 {
433 ASIO_ASSERT(n == 0 && "iterator out of bounds");
434 current_buffer_ = buffer_type();
435 current_buffer_position_ = 0;
436 return;
437 }
438 current_buffer_ = *current_;
439 current_buffer_position_ = 0;
440 }
441 }
442 else if (n < 0)
443 {
444 std::size_t abs_n = -n;
445 ASIO_ASSERT(position_ >= abs_n && "iterator out of bounds");
446 for (;;)
447 {
448 // Check if the advance can be satisfied by the current buffer.
449 if (current_buffer_position_ >= abs_n)
450 {
451 position_ -= abs_n;
452 current_buffer_position_ -= abs_n;
453 return;
454 }
455
456 // Update position.
457 abs_n -= current_buffer_position_;
458 position_ -= current_buffer_position_;
459
460 // Check if we've reached the beginning of the buffers.
461 if (current_ == begin_)
462 {
463 ASIO_ASSERT(abs_n == 0 && "iterator out of bounds");
464 current_buffer_position_ = 0;

Callers 8

get_characterMethod · 0.85
json.hppFile · 0.85
iter_impl.hppFile · 0.85
get_characterMethod · 0.85
prepareMethod · 0.85
consumeMethod · 0.85
processMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected