summaryrefslogtreecommitdiff
path: root/boost/thread/csbl/devector.hpp
blob: c11ad29ba15d5e33257b9f616f4f823cd3625d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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 BOOST_CSBL_DEVECTOR_HPP
#define BOOST_CSBL_DEVECTOR_HPP

#include <boost/config.hpp>

#include <boost/thread/csbl/vector.hpp>
#include <boost/move/detail/move_helpers.hpp>

namespace boost
{
  namespace csbl
  {
    template <class T>
    class devector
    {
      typedef vector<T> vector_type;
      vector<T> data_;
      std::size_t front_index_;

      BOOST_COPYABLE_AND_MOVABLE(devector)

      template <class U>
      void priv_push_back(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) BOOST_NOEXCEPT
         :  data_(x.data_),
            front_index_(x.front_index_)
      {}
      devector(BOOST_RV_REF(devector) x) BOOST_NOEXCEPT
         :  data_(boost::move(x.data_)),
            front_index_(x.front_index_)
      {}

      devector& operator=(BOOST_COPY_ASSIGN_REF(devector) x)
      {
         if (&x != this)
         {
           data_ = x.data_;
           front_index_ = x.front_index_;
         }
         return *this;
      }

      devector& operator=(BOOST_RV_REF(devector) x)
         BOOST_NOEXCEPT_IF(vector<T>::allocator_traits_type::propagate_on_container_move_assignment::value)
      {
        data_ = boost::move(x.data_);
        front_index_ = x.front_index_;
        return *this;
      }

      bool empty() const BOOST_NOEXCEPT
      { return data_.size() == front_index_; }

      size_type size() const BOOST_NOEXCEPT
      { return data_.size() - front_index_; }

      reference         front() BOOST_NOEXCEPT
      { return data_[front_index_]; }

      const_reference         front() const BOOST_NOEXCEPT
      { return data_[front_index_]; }

      reference         back() BOOST_NOEXCEPT
      { return data_.back(); }

      const_reference         back() const BOOST_NOEXCEPT
      { return data_.back(); }

      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