Files

103 lines
2.7 KiB
C++

// Copyright (C) 2013 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// 2013/10 Vicente J. Botet Escriba
// Creation.
#ifndef ACTIV_BOOST_CSBL_DEVECTOR_HPP
#define ACTIV_BOOST_CSBL_DEVECTOR_HPP
#include <ActivBoost/config.hpp>
#include <ActivBoost/thread/csbl/vector.hpp>
#include <ActivBoost/move/detail/move_helpers.hpp>
namespace Boost
{
namespace csbl
{
template <class T>
class devector
{
typedef csbl::vector<T> vector_type;
vector_type data_;
std::size_t front_index_;
ACTIV_BOOST_COPYABLE_AND_MOVABLE(devector)
template <class U>
void priv_push_back(ACTIV_BOOST_FWD_REF(U) x)
{ data_.push_back(Boost::forward<U>(x)); }
public:
typedef typename vector_type::size_type size_type;
typedef typename vector_type::reference reference;
typedef typename vector_type::const_reference const_reference;
devector() : front_index_(0) {}
devector(devector const& x) ACTIV_BOOST_NOEXCEPT
: data_(x.data_),
front_index_(x.front_index_)
{}
devector(ACTIV_BOOST_RV_REF(devector) x) ACTIV_BOOST_NOEXCEPT
: data_(Boost::move(x.data_)),
front_index_(x.front_index_)
{}
devector& operator=(ACTIV_BOOST_COPY_ASSIGN_REF(devector) x)
{
if (&x != this)
{
data_ = x.data_;
front_index_ = x.front_index_;
}
return *this;
}
devector& operator=(ACTIV_BOOST_RV_REF(devector) x)
#if defined ACTIV_BOOST_THREAD_USES_ACTIV_BOOST_VECTOR
ACTIV_BOOST_NOEXCEPT_IF(vector_type::allocator_traits_type::propagate_on_container_move_assignment::value)
#endif
{
data_ = Boost::move(x.data_);
front_index_ = x.front_index_;
return *this;
}
bool empty() const ACTIV_BOOST_NOEXCEPT
{ return data_.size() == front_index_; }
size_type size() const ACTIV_BOOST_NOEXCEPT
{ return data_.size() - front_index_; }
reference front() ACTIV_BOOST_NOEXCEPT
{ return data_[front_index_]; }
const_reference front() const ACTIV_BOOST_NOEXCEPT
{ return data_[front_index_]; }
reference back() ACTIV_BOOST_NOEXCEPT
{ return data_.back(); }
const_reference back() const ACTIV_BOOST_NOEXCEPT
{ return data_.back(); }
ACTIV_BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
void pop_front()
{
++front_index_;
if (empty()) {
data_.clear();
front_index_=0;
}
}
};
}
}
#endif // header