• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2013 Vicente J. Botet Escriba
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 //
6 // 2013/10 Vicente J. Botet Escriba
7 //   Creation.
8 
9 #ifndef BOOST_CSBL_DEVECTOR_HPP
10 #define BOOST_CSBL_DEVECTOR_HPP
11 
12 #include <boost/config.hpp>
13 
14 #include <boost/thread/csbl/vector.hpp>
15 #include <boost/move/detail/move_helpers.hpp>
16 
17 namespace boost
18 {
19   namespace csbl
20   {
21     template <class T>
22     class devector
23     {
24       typedef csbl::vector<T> vector_type;
25       vector_type data_;
26       std::size_t front_index_;
27 
BOOST_COPYABLE_AND_MOVABLE(devector)28       BOOST_COPYABLE_AND_MOVABLE(devector)
29 
30       template <class U>
31       void priv_push_back(BOOST_FWD_REF(U) x)
32       { data_.push_back(boost::forward<U>(x)); }
33 
34     public:
35       typedef typename vector_type::size_type size_type;
36       typedef typename vector_type::reference reference;
37       typedef typename vector_type::const_reference const_reference;
38 
39 
devector()40       devector() : front_index_(0) {}
devector(devector const & x)41       devector(devector const& x) BOOST_NOEXCEPT
42          :  data_(x.data_),
43             front_index_(x.front_index_)
44       {}
devector(BOOST_RV_REF (devector)x)45       devector(BOOST_RV_REF(devector) x) BOOST_NOEXCEPT
46          :  data_(boost::move(x.data_)),
47             front_index_(x.front_index_)
48       {}
49 
operator =(BOOST_COPY_ASSIGN_REF (devector)x)50       devector& operator=(BOOST_COPY_ASSIGN_REF(devector) x)
51       {
52          if (&x != this)
53          {
54            data_ = x.data_;
55            front_index_ = x.front_index_;
56          }
57          return *this;
58       }
59 
operator =(BOOST_RV_REF (devector)x)60       devector& operator=(BOOST_RV_REF(devector) x)
61 #if defined BOOST_THREAD_USES_BOOST_VECTOR
62          BOOST_NOEXCEPT_IF(vector_type::allocator_traits_type::propagate_on_container_move_assignment::value)
63 #endif
64       {
65         data_ = boost::move(x.data_);
66         front_index_ = x.front_index_;
67         return *this;
68       }
69 
empty() const70       bool empty() const BOOST_NOEXCEPT
71       { return data_.size() == front_index_; }
72 
size() const73       size_type size() const BOOST_NOEXCEPT
74       { return data_.size() - front_index_; }
75 
front()76       reference         front() BOOST_NOEXCEPT
77       { return data_[front_index_]; }
78 
front() const79       const_reference         front() const BOOST_NOEXCEPT
80       { return data_[front_index_]; }
81 
back()82       reference         back() BOOST_NOEXCEPT
83       { return data_.back(); }
84 
back() const85       const_reference         back() const BOOST_NOEXCEPT
86       { return data_.back(); }
87 
BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back,T,void,priv_push_back)88       BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
89 
90       void pop_front()
91       {
92         ++front_index_;
93         if (empty()) {
94           data_.clear();
95           front_index_=0;
96         }
97        }
98 
99     };
100   }
101 }
102 #endif // header
103