1 #ifndef BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP
2 #define BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP
4 //////////////////////////////////////////////////////////////////////////////
6 // (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost
7 // Software License, Version 1.0. (See accompanying file
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/thread for documentation.
12 //////////////////////////////////////////////////////////////////////////////
14 #include <boost/thread/detail/config.hpp>
15 #include <boost/thread/detail/move.hpp>
16 #include <boost/thread/concurrent_queues/queue_op_status.hpp>
17 #include <boost/thread/concurrent_queues/deque_base.hpp>
19 #include <boost/config/abi_prefix.hpp>
28 template <typename Queue>
29 class deque_adaptor_copyable_only :
30 public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
34 typedef typename Queue::value_type value_type;
35 typedef typename Queue::size_type size_type;
37 // Constructors/Assignment/Destructors
38 deque_adaptor_copyable_only() {}
41 bool empty() const { return queue.empty(); }
42 bool full() const { return queue.full(); }
43 size_type size() const { return queue.size(); }
44 bool closed() const { return queue.closed(); }
47 void close() { queue.close(); }
49 void push_back(const value_type& x) { queue.push_back(x); }
51 void pull_front(value_type& x) { queue.pull_front(x); };
52 value_type pull_front() { return queue.pull_front(); }
54 queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); }
55 queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
57 queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); }
58 queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
60 queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); }
61 queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
64 template <typename Queue>
65 class deque_adaptor_movable_only :
66 public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
70 typedef typename Queue::value_type value_type;
71 typedef typename Queue::size_type size_type;
73 // Constructors/Assignment/Destructors
75 deque_adaptor_movable_only() {}
78 bool empty() const { return queue.empty(); }
79 bool full() const { return queue.full(); }
80 size_type size() const { return queue.size(); }
81 bool closed() const { return queue.closed(); }
84 void close() { queue.close(); }
87 void pull_front(value_type& x) { queue.pull_front(x); };
88 // enable_if is_nothrow_copy_movable<value_type>
89 value_type pull_front() { return queue.pull_front(); }
91 queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
93 queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
95 queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
97 void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); }
98 queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); }
99 queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); }
100 queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); }
103 template <typename Queue>
104 class deque_adaptor_copyable_and_movable :
105 public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
109 typedef typename Queue::value_type value_type;
110 typedef typename Queue::size_type size_type;
112 // Constructors/Assignment/Destructors
114 deque_adaptor_copyable_and_movable() {}
117 bool empty() const { return queue.empty(); }
118 bool full() const { return queue.full(); }
119 size_type size() const { return queue.size(); }
120 bool closed() const { return queue.closed(); }
123 void close() { queue.close(); }
126 void push_back(const value_type& x) { queue.push_back(x); }
128 void pull_front(value_type& x) { queue.pull_front(x); };
129 // enable_if is_nothrow_copy_movable<value_type>
130 value_type pull_front() { return queue.pull_front(); }
132 queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); }
133 queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
135 queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); }
136 queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
138 queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); }
139 queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
141 void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); }
142 queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); }
143 queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); }
144 queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); }
148 template <class Q, class T,
149 #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
150 #if defined __GNUC__ && ! defined __clang__
151 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
152 bool Copyable = is_copy_constructible<T>::value,
155 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
156 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
158 #elif defined _MSC_VER
160 bool Copyable = is_copy_constructible<T>::value,
163 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
164 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
167 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
168 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
171 bool Copyable = is_copy_constructible<T>::value,
172 bool Movable = has_move_emulation_enabled<T>::value
175 struct deque_adaptor;
177 template <class Q, class T>
178 struct deque_adaptor<Q, T, true, true> {
179 typedef deque_adaptor_copyable_and_movable<Q> type;
181 template <class Q, class T>
182 struct deque_adaptor<Q, T, true, false> {
183 typedef deque_adaptor_copyable_only<Q> type;
185 template <class Q, class T>
186 struct deque_adaptor<Q, T, false, true> {
187 typedef deque_adaptor_movable_only<Q> type;
192 template <typename Queue>
193 class deque_adaptor :
194 public detail::deque_adaptor<Queue, typename Queue::value_type>::type
197 typedef typename Queue::value_type value_type;
198 typedef typename Queue::size_type size_type;
199 // Constructors/Assignment/Destructors
200 virtual ~deque_adaptor() {};
203 using concurrent::deque_adaptor;
207 #include <boost/config/abi_suffix.hpp>