Skip to content

Commit

Permalink
[FOLD] buffer_cat
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Nov 9, 2016
1 parent 07bcecc commit 8235c5f
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions include/beast/core/detail/buffer_cat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ class buffer_cat_helper<Bn...>::const_iterator
std::tuple<Bn...> const& bn, bool at_end);

void
construct(C<sizeof...(Bn)>)
construct(C<sizeof...(Bn)> const&)
{
auto constexpr I = sizeof...(Bn);
n_ = I;
}

template<std::size_t I>
void
construct(C<I>)
construct(C<I> const&)
{
if(std::get<I>(*bn_).begin() !=
std::get<I>(*bn_).end())
Expand All @@ -174,14 +174,14 @@ class buffer_cat_helper<Bn...>::const_iterator
}

void
destroy(C<sizeof...(Bn)>)
destroy(C<sizeof...(Bn)> const&)
{
return;
}

template<std::size_t I>
void
destroy(C<I>)
destroy(C<I> const&)
{
if(n_ == I)
{
Expand All @@ -193,67 +193,72 @@ class buffer_cat_helper<Bn...>::const_iterator
}

void
move(C<sizeof...(Bn)>, const_iterator&&)
move(const_iterator&&,
C<sizeof...(Bn)> const&)
{
}

template<std::size_t I>
void
move(C<I>, const_iterator&& other)
move(const_iterator&& other,
C<I> const&)
{
if(n_ == I)
{
new(buf_.data()) iter_t<I>{
std::move(other.iter<I>())};
return;
}
move(C<I+1>{}, std::move(other));
move(std::move(other), C<I+1>{});
}

void
copy(C<sizeof...(Bn)>, const_iterator const&)
copy(const_iterator const&,
C<sizeof...(Bn)> const&)
{
}

template<std::size_t I>
void
copy(C<I>, const_iterator const& other)
copy(const_iterator const& other,
C<I> const&)
{
if(n_ == I)
{
new(buf_.data()) iter_t<I>{
other.iter<I>()};
return;
}
copy(C<I+1>{}, other);
copy(other, C<I+1>{});
}

bool
equal(C<sizeof...(Bn)>,
const_iterator const&) const
equal(const_iterator const&,
C<sizeof...(Bn)> const&) const
{
return true;
}

template<std::size_t I>
bool
equal(C<I>, const_iterator const& other) const
equal(const_iterator const& other,
C<I> const&) const
{
if(n_ == I)
return iter<I>() == other.iter<I>();
return equal(C<I+1>{}, other);
return equal(other, C<I+1>{});
}

[[noreturn]]
reference
dereference(C<sizeof...(Bn)>) const
dereference(C<sizeof...(Bn)> const&) const
{
throw std::logic_error("invalid iterator");
}

template<std::size_t I>
reference
dereference(C<I>) const
dereference(C<I> const&) const
{
if(n_ == I)
return *iter<I>();
Expand All @@ -262,14 +267,14 @@ class buffer_cat_helper<Bn...>::const_iterator

[[noreturn]]
void
increment(C<sizeof...(Bn)>)
increment(C<sizeof...(Bn)> const&)
{
throw std::logic_error("invalid iterator");
}

template<std::size_t I>
void
increment(C<I>)
increment(C<I> const&)
{
if(n_ == I)
{
Expand All @@ -284,7 +289,7 @@ class buffer_cat_helper<Bn...>::const_iterator
}

void
decrement(C<sizeof...(Bn)>)
decrement(C<sizeof...(Bn)> const&)
{
auto constexpr I = sizeof...(Bn);
if(n_ == I)
Expand All @@ -297,7 +302,7 @@ class buffer_cat_helper<Bn...>::const_iterator
}

void
decrement(C<0>)
decrement(C<0> const&)
{
auto constexpr I = 0;
if(iter<I>() != std::get<I>(*bn_).begin())
Expand All @@ -310,7 +315,7 @@ class buffer_cat_helper<Bn...>::const_iterator

template<std::size_t I>
void
decrement(C<I>)
decrement(C<I> const&)
{
if(n_ == I)
{
Expand Down Expand Up @@ -364,7 +369,7 @@ const_iterator::const_iterator(const_iterator&& other)
: n_(other.n_)
, bn_(other.bn_)
{
move(C<0>{}, std::move(other));
move(std::move(other), C<0>{});
}

template<class... Bn>
Expand All @@ -373,7 +378,7 @@ const_iterator::const_iterator(const_iterator const& other)
: n_(other.n_)
, bn_(other.bn_)
{
copy(C<0>{}, other);
copy(other, C<0>{});
}

template<class... Bn>
Expand All @@ -387,7 +392,7 @@ const_iterator::operator=(const_iterator&& other) ->
destroy(C<0>{});
n_ = other.n_;
bn_ = other.bn_;
move(C<0>{}, std::move(other));
move(std::move(other), C<0>{});
return *this;
}

Expand All @@ -402,7 +407,7 @@ const_iterator&
destroy(C<0>{});
n_ = other.n_;
bn_ = other.bn_;
copy(C<0>{}, other);
copy(other, C<0>{});
return *this;
}

Expand All @@ -415,7 +420,7 @@ const_iterator::operator==(const_iterator const& other) const
return false;
if(n_ != other.n_)
return false;
return equal(C<0>{}, other);
return equal(other, C<0>{});
}

template<class... Bn>
Expand Down Expand Up @@ -448,19 +453,21 @@ const_iterator::operator--() ->
}

template<class... Bn>
inline
auto
buffer_cat_helper<Bn...>::begin() const ->
const_iterator
{
return const_iterator(bn_, false);
return const_iterator{bn_, false};
}

template<class... Bn>
inline
auto
buffer_cat_helper<Bn...>::end() const ->
const_iterator
{
return const_iterator(bn_, true);
return const_iterator{bn_, true};
}

} // detail
Expand Down

0 comments on commit 8235c5f

Please sign in to comment.