2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H
32 #define CDSLIB_IMPL_BOUNDED_ARRAY_H
35 Dynamic non-growing array
38 2008.03.08 Maxim.Khiszinsky Created
41 #include <cds/details/allocator.h>
48 /// Bounded dynamic array
50 The class template is intended for storing fixed-size sequences of objects.
51 Array capacity is constant and cannot be changed after creation of object of the class.
52 It is suitable for managing objects of non-copyable type \p T.
54 \par Template parameters
55 - \p T type of elements
56 - \p Allocator dynamic memory allocator class (<tt>std::allocator</tt> semantics)
59 template <typename T, class Allocator = CDS_DEFAULT_ALLOCATOR >
63 typedef T value_type ; ///< value type stored in the array
64 typedef Allocator allocator_type ; ///< allocator type
66 typedef value_type * iterator ; ///< item iterator
67 typedef value_type const * const_iterator ; ///< item const iterator
70 typedef cds::details::Allocator< T, allocator_type> allocator_impl;
73 const size_t m_nCapacity;
77 explicit bounded_array(
78 size_t nCapacity ///< capacity
80 : m_arr( allocator_impl().NewArray( nCapacity ))
81 , m_nCapacity( nCapacity )
86 allocator_impl().Delete( m_arr, capacity());
89 const value_type& operator []( size_t nItem ) const
91 assert( nItem < capacity());
95 value_type& operator []( size_t nItem )
97 assert( nItem < capacity());
101 size_t size() const CDS_NOEXCEPT
106 size_t capacity() const CDS_NOEXCEPT
111 /// Returns pointer to the first item in the array
112 value_type * top() CDS_NOEXCEPT
117 /// Get begin iterator
118 const_iterator begin() const CDS_NOEXCEPT
122 iterator begin() CDS_NOEXCEPT
128 const_iterator end() const CDS_NOEXCEPT
130 return begin() + capacity();
132 iterator end() CDS_NOEXCEPT
134 return begin() + capacity();
138 } // namespace details
142 #endif // #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H