1 #ifndef BOOST_THREAD_QUEUE_ADAPTOR_HPP
2 #define BOOST_THREAD_QUEUE_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/queue_base.hpp>
19 #include <boost/config/abi_prefix.hpp>
28 template <typename Queue>
29 class queue_adaptor_copyable_only :
30 public boost::queue_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 queue_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(const value_type& x) { queue.push(x); }
51 void pull(value_type& x) { queue.pull(x); };
52 value_type pull() { return queue.pull(); }
54 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
55 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
57 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
58 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
60 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
61 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
64 template <typename Queue>
65 class queue_adaptor_movable_only :
66 public boost::queue_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 queue_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(value_type& x) { queue.pull(x); };
88 // enable_if is_nothrow_copy_movable<value_type>
89 value_type pull() { return queue.pull(); }
91 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
93 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
95 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
97 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
98 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
99 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
100 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); }
103 template <typename Queue>
104 class queue_adaptor_copyable_and_movable :
105 public boost::queue_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 queue_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(const value_type& x) { queue.push(x); }
128 void pull(value_type& x) { queue.pull(x); };
129 // enable_if is_nothrow_copy_movable<value_type>
130 value_type pull() { return queue.pull(); }
132 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
133 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
135 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
136 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
138 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
139 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
141 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
142 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
143 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
144 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(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 queue_adaptor;
177 template <class Q, class T>
178 struct queue_adaptor<Q, T, true, true> {
179 typedef queue_adaptor_copyable_and_movable<Q> type;
181 template <class Q, class T>
182 struct queue_adaptor<Q, T, true, false> {
183 typedef queue_adaptor_copyable_only<Q> type;
185 template <class Q, class T>
186 struct queue_adaptor<Q, T, false, true> {
187 typedef queue_adaptor_movable_only<Q> type;
192 template <typename Queue>
193 class queue_adaptor :
194 public detail::queue_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 ~queue_adaptor() {};
203 using concurrent::queue_adaptor;
207 #include <boost/config/abi_suffix.hpp>