buffer_view skips empty buffer sequences

This commit is contained in:
Vinnie Falco
2017-05-28 12:57:41 -07:00
parent c29974eec9
commit 056bf5ff99
2 changed files with 49 additions and 22 deletions

View File

@ -6,6 +6,7 @@ Version 45
* Add test::pipe * Add test::pipe
* Fix header::reason * Fix header::reason
* Documentation work * Documentation work
* buffer_view skips empty buffer sequences
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -125,8 +125,8 @@ private:
void void
construct(C<I> const&) construct(C<I> const&)
{ {
if(std::get<I>(*bn_).begin() != if(boost::asio::buffer_size(
std::get<I>(*bn_).end()) std::get<I>(*bn_)) != 0)
{ {
n_ = I; n_ = I;
new(&buf_[0]) iter_t<I>{ new(&buf_[0]) iter_t<I>{
@ -136,6 +136,37 @@ private:
construct(C<I+1>{}); construct(C<I+1>{});
} }
void
rconstruct(C<0> const&)
{
auto constexpr I = 0;
if(boost::asio::buffer_size(
std::get<I>(*bn_)) != 0)
{
n_ = I;
new(&buf_[0]) iter_t<I>{
std::get<I>(*bn_).end()};
return;
}
BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator"});
}
template<std::size_t I>
void
rconstruct(C<I> const&)
{
if(boost::asio::buffer_size(
std::get<I>(*bn_)) != 0)
{
n_ = I;
new(&buf_[0]) iter_t<I>{
std::get<I>(*bn_).end()};
return;
}
rconstruct(C<I-1>{});
}
void void
destroy(C<sizeof...(Bn)> const&) destroy(C<sizeof...(Bn)> const&)
{ {
@ -258,27 +289,10 @@ private:
{ {
auto constexpr I = sizeof...(Bn); auto constexpr I = sizeof...(Bn);
if(n_ == I) if(n_ == I)
{ rconstruct(C<I-1>{});
--n_;
new(&buf_[0]) iter_t<I-1>{
std::get<I-1>(*bn_).end()};
}
decrement(C<I-1>{}); decrement(C<I-1>{});
} }
void
decrement(C<0> const&)
{
auto constexpr I = 0;
if(iter<I>() != std::get<I>(*bn_).begin())
{
--iter<I>();
return;
}
BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator"});
}
template<std::size_t I> template<std::size_t I>
void void
decrement(C<I> const&) decrement(C<I> const&)
@ -293,11 +307,23 @@ private:
--n_; --n_;
using Iter = iter_t<I>; using Iter = iter_t<I>;
iter<I>().~Iter(); iter<I>().~Iter();
new(&buf_[0]) iter_t<I-1>{ rconstruct(C<I-1>{});
std::get<I-1>(*bn_).end()};
} }
decrement(C<I-1>{}); decrement(C<I-1>{});
} }
void
decrement(C<0> const&)
{
auto constexpr I = 0;
if(iter<I>() != std::get<I>(*bn_).begin())
{
--iter<I>();
return;
}
BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator"});
}
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------