3 #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H
4 #define CDSLIB_IMPL_BOUNDED_ARRAY_H
7 Dynamic non-growing array
10 2008.03.08 Maxim.Khiszinsky Created
13 #include <cds/details/allocator.h>
20 /// Bounded dynamic array
22 The class template is intended for storing fixed-size sequences of objects.
23 Array capacity is constant and cannot be changed after creation of object of the class.
24 It is suitable for managing objects of non-copyable type \p T.
26 \par Template parameters
27 - \p T type of elements
28 - \p Allocator dynamic memory allocator class (<tt>std::allocator</tt> semantics)
31 template <typename T, class Allocator = CDS_DEFAULT_ALLOCATOR >
35 typedef T value_type ; ///< value type stored in the array
36 typedef Allocator allocator_type ; ///< allocator type
38 typedef value_type * iterator ; ///< item iterator
39 typedef value_type const * const_iterator ; ///< item const iterator
42 typedef cds::details::Allocator< T, allocator_type> allocator_impl;
45 const size_t m_nCapacity;
49 explicit bounded_array(
50 size_t nCapacity ///< capacity
52 : m_arr( allocator_impl().NewArray( nCapacity ) )
53 , m_nCapacity( nCapacity )
58 allocator_impl().Delete( m_arr, capacity() );
61 const value_type& operator []( size_t nItem ) const
63 assert( nItem < capacity() );
67 value_type& operator []( size_t nItem )
69 assert( nItem < capacity() );
73 size_t size() const CDS_NOEXCEPT
78 size_t capacity() const CDS_NOEXCEPT
83 /// Returns pointer to the first item in the array
84 value_type * top() CDS_NOEXCEPT
89 /// Get begin iterator
90 const_iterator begin() const CDS_NOEXCEPT
94 iterator begin() CDS_NOEXCEPT
100 const_iterator end() const CDS_NOEXCEPT
102 return begin() + capacity();
104 iterator end() CDS_NOEXCEPT
106 return begin() + capacity();
110 } // namespace details
114 #endif // #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H