+ value_type * m_buffer;
+ size_t const m_nCapacity;
+ //@endcond
+ public:
+ /// Allocates dynamic buffer of given \p nCapacity
+ /**
+ If \p Exp2 class template parameter is \p true then actual capacity
+ of allocating buffer is nearest upper to \p nCapacity power of two.
+ */
+ uninitialized_dynamic_buffer( size_t nCapacity )
+ : m_nCapacity( c_bExp2 ? beans::ceil2(nCapacity) : nCapacity )
+ {
+ assert( m_nCapacity >= 2 );
+ // Capacity must be power of 2
+ assert( !c_bExp2 || (m_nCapacity & (m_nCapacity - 1)) == 0 );
+
+ m_buffer = allocator_type().allocate( m_nCapacity );
+ }
+
+ /// Destroys dynamically allocated buffer
+ ~uninitialized_dynamic_buffer()
+ {
+ allocator_type().deallocate( m_buffer, m_nCapacity );
+ }
+
+ uninitialized_dynamic_buffer( const uninitialized_dynamic_buffer& ) = delete;
+ uninitialized_dynamic_buffer& operator =( const uninitialized_dynamic_buffer& ) = delete;
+
+ /// Get item \p i
+ value_type& operator []( size_t i )
+ {
+ assert( i < capacity());
+ return m_buffer[i];
+ }
+
+ /// Get item \p i, const version
+ const value_type& operator []( size_t i ) const
+ {
+ assert( i < capacity());
+ return m_buffer[i];
+ }
+
+ /// Returns buffer capacity
+ size_t capacity() const CDS_NOEXCEPT
+ {
+ return m_nCapacity;
+ }
+
+ /// Zeroize the buffer
+ void zeroize()
+ {
+ memset( m_buffer, 0, capacity() * sizeof(m_buffer[0]));
+ }
+
+ /// Returns pointer to buffer array
+ value_type * buffer() CDS_NOEXCEPT
+ {
+ return m_buffer;
+ }
+
+ /// Returns pointer to buffer array
+ value_type * buffer() const CDS_NOEXCEPT
+ {
+ return m_buffer;
+ }
+
+ /// Returns <tt> idx % capacity() </tt>
+ /**
+ If the buffer size is a power of two, binary arithmethics is used
+ instead of modulo arithmetics
+ */
+ size_t mod( size_t idx )
+ {
+ static_if ( c_bExp2 )
+ return idx & ( capacity() - 1 );
+ else
+ return idx % capacity();
+ }
+
+ //@cond
+ template <typename I>
+ typename std::enable_if< sizeof( I ) != sizeof( size_t ), size_t >::type mod( I idx )
+ {
+ static_if ( c_bExp2 )
+ return static_cast<size_t>( idx & static_cast<I>( capacity() - 1 ));
+ else
+ return static_cast<size_t>( idx % capacity());
+ }