#include <boost/aligned_storage.hpp>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
+#include <boost/core/allocator_access.hpp>
#include <boost/utility.hpp>
+#include <boost/next_prior.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/config.hpp> // for BOOST_LIKELY
{
typedef std::size_t size_type;
size_type max_elements_;
+#ifdef BOOST_NO_CXX11_ALLOCATOR
typedef typename Alloc::pointer pointer;
+#else
+ typedef std::allocator_traits<Alloc> allocator_traits;
+ typedef typename allocator_traits::pointer pointer;
+#endif
pointer array_;
protected:
explicit runtime_sized_ringbuffer(size_type max_elements):
max_elements_(max_elements + 1)
{
+#ifdef BOOST_NO_CXX11_ALLOCATOR
array_ = Alloc::allocate(max_elements_);
+#else
+ Alloc& alloc = *this;
+ array_ = allocator_traits::allocate(alloc, max_elements_);
+#endif
}
template <typename U>
- runtime_sized_ringbuffer(typename Alloc::template rebind<U>::other const & alloc, size_type max_elements):
+ runtime_sized_ringbuffer(typename boost::allocator_rebind<Alloc, U>::type const & alloc, size_type max_elements):
Alloc(alloc), max_elements_(max_elements + 1)
{
+#ifdef BOOST_NO_CXX11_ALLOCATOR
array_ = Alloc::allocate(max_elements_);
+#else
+ Alloc& allocator = *this;
+ array_ = allocator_traits::allocate(allocator, max_elements_);
+#endif
}
runtime_sized_ringbuffer(Alloc const & alloc, size_type max_elements):
Alloc(alloc), max_elements_(max_elements + 1)
{
+#ifdef BOOST_NO_CXX11_ALLOCATOR
array_ = Alloc::allocate(max_elements_);
+#else
+ Alloc& allocator = *this;
+ array_ = allocator_traits::allocate(allocator, max_elements_);
+#endif
}
~runtime_sized_ringbuffer(void)
T out;
while (pop(&out, 1)) {}
+#ifdef BOOST_NO_CXX11_ALLOCATOR
Alloc::deallocate(array_, max_elements_);
+#else
+ Alloc& allocator = *this;
+ allocator_traits::deallocate(allocator, array_, max_elements_);
+#endif
}
bool push(T const & t)
*
* \pre spsc_queue must be configured to be sized at compile-time
*/
- // @{
spsc_queue(void)
{
+ // Don't use BOOST_STATIC_ASSERT() here since it will be evaluated when compiling
+ // this function and this function may be compiled even when it isn't being used.
BOOST_ASSERT(!runtime_sized);
}
+ /** Constructs a spsc_queue with a custom allocator
+ *
+ * \pre spsc_queue must be configured to be sized at compile-time
+ *
+ * \note This is just for API compatibility: an allocator isn't actually needed
+ */
template <typename U>
- explicit spsc_queue(typename allocator::template rebind<U>::other const &)
+ explicit spsc_queue(typename boost::allocator_rebind<allocator, U>::type const &)
{
- // just for API compatibility: we don't actually need an allocator
BOOST_STATIC_ASSERT(!runtime_sized);
}
+ /** Constructs a spsc_queue with a custom allocator
+ *
+ * \pre spsc_queue must be configured to be sized at compile-time
+ *
+ * \note This is just for API compatibility: an allocator isn't actually needed
+ */
explicit spsc_queue(allocator const &)
{
- // just for API compatibility: we don't actually need an allocator
+ // Don't use BOOST_STATIC_ASSERT() here since it will be evaluated when compiling
+ // this function and this function may be compiled even when it isn't being used.
BOOST_ASSERT(!runtime_sized);
}
- // @}
-
/** Constructs a spsc_queue for element_count elements
*
* \pre spsc_queue must be configured to be sized at run-time
*/
- // @{
explicit spsc_queue(size_type element_count):
base_type(element_count)
{
+ // Don't use BOOST_STATIC_ASSERT() here since it will be evaluated when compiling
+ // this function and this function may be compiled even when it isn't being used.
BOOST_ASSERT(runtime_sized);
}
+ /** Constructs a spsc_queue for element_count elements with a custom allocator
+ *
+ * \pre spsc_queue must be configured to be sized at run-time
+ */
template <typename U>
- spsc_queue(size_type element_count, typename allocator::template rebind<U>::other const & alloc):
+ spsc_queue(size_type element_count, typename boost::allocator_rebind<allocator, U>::type const & alloc):
base_type(alloc, element_count)
{
BOOST_STATIC_ASSERT(runtime_sized);
}
+ /** Constructs a spsc_queue for element_count elements with a custom allocator
+ *
+ * \pre spsc_queue must be configured to be sized at run-time
+ */
spsc_queue(size_type element_count, allocator_arg const & alloc):
base_type(alloc, element_count)
{
+ // Don't use BOOST_STATIC_ASSERT() here since it will be evaluated when compiling
+ // this function and this function may be compiled even when it isn't being used.
BOOST_ASSERT(runtime_sized);
}
- // @}
/** Pushes object t to the ringbuffer.
*