55#ifndef __ADS_SmallVector
56 #define __ADS_SmallVector
68#include <initializer_list>
76#if defined( ADS_WITH_BOOST ) && ! defined( ADS_SMALLVECTOR_BOOST )
77 #define ADS_SMALLVECTOR_BOOST 1
79#ifndef ADS_SMALLVECTOR_BOOST
80 #define ADS_SMALLVECTOR_BOOST 0
82#if ADS_SMALLVECTOR_BOOST
83 #include <boost/container/options.hpp>
84 #include <boost/container/small_vector.hpp>
99template<
class T , std::
size_t N = 8 ,
class A = std::allocator< T > >
102 :
private detail::AllocHolder< detail::RebindAlloc< A , T > >
105#if ! ADS_SMALLVECTOR_BOOST
107 using Holder = detail::AllocHolder< detail::RebindAlloc< A , T > >;
109 using Traits = std::allocator_traits< detail::RebindAlloc< A , T > >;
114 static constexpr bool PLAIN =
115 detail::alwaysEqualAlloc< A > && std::is_default_constructible_v< A >;
117 static_assert( N >= 1 ,
"room for one item at least" );
145#if ! ADS_SMALLVECTOR_BOOST
152#if ! ADS_SMALLVECTOR_BOOST
154 : Holder( alloc ) , f_A( inner() ) { }
157 : f_v(
typename Vector::allocator_type( alloc ) ) { }
167 template< std::input_iterator I , std::sentinel_for< I > S >
185 std::is_nothrow_move_constructible_v< T > );
199 return( detail::copyAssign( *
this , other ) );
204 std::is_nothrow_move_constructible_v< T > )
212 return( detail::moveAssign( *
this , std::move( other ) ) );
220#if ! ADS_SMALLVECTOR_BOOST
234 [[nodiscard]]
bool empty(
void )
const {
return(
size() == 0 ); }
236#if ! ADS_SMALLVECTOR_BOOST
238 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
241 [[nodiscard]] std::size_t
capacity(
void )
const {
return( f_cap ); }
244 [[nodiscard]]
bool small(
void )
const {
return( f_A == inner() ); }
247 [[nodiscard]] T *
data(
void ) {
return( f_A ); }
249 [[nodiscard]]
const T *
data(
void )
const {
return( f_A ); }
252 [[nodiscard]] std::size_t
size(
void )
const {
return( f_v.size() ); }
255 [[nodiscard]] std::size_t
capacity(
void )
const {
256 return( f_v.capacity() );
261 [[nodiscard]]
bool small(
void )
const {
262 return( f_v.capacity() == Vector::internal_capacity() );
266 [[nodiscard]] T *
data(
void ) {
return( f_v.data() ); }
268 [[nodiscard]]
const T *
data(
void )
const {
return( f_v.data() ); }
304 return(
data()[ i ] );
310 return(
data()[ i ] );
317 return(
data()[ 0 ] );
321 [[nodiscard]]
const T &
front(
void )
const {
323 return(
data()[ 0 ] );
327 [[nodiscard]] T &
back(
void ) {
333 [[nodiscard]]
const T &
back(
void )
const {
365 template<
class... Args >
376 void resize( std::size_t n ,
const T & x = T() );
388#if ! ADS_SMALLVECTOR_BOOST
389 T * inner(
void ) {
return(
reinterpret_cast< T *
>( f_room ) ); }
390 const T * inner(
void )
const {
391 return(
reinterpret_cast< const T *
>( f_room ) );
396 void grow( std::size_t c );
403 std::size_t f_cap = N;
405 alignas( T )
unsigned char f_room[ N *
sizeof( T ) ];
409 boost::container::growth_factor< boost::container::growth_factor_100 >;
413 using Vector = boost::container::small_vector<
414 T , N , detail::RebindAlloc< A , T > ,
415 typename boost::container::small_vector_options< Doubling >::type >;
418 void renew(
void )
noexcept;
433#include "ADS/sequence/impl/SmallVector.tpp"
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
#define ADS_SMALLVECTOR_BOOST
Definition SmallVector.h:80
const T & front(void) const
the first item, constant
Definition SmallVector.h:321
void swap(SmallVector &other)
exchanges the items with other
bool empty(void) const
true if there is no item
Definition SmallVector.h:234
std::ptrdiff_t difference_type
the type of the distances
Definition SmallVector.h:126
iterator end(void)
the iterator past the last item
Definition SmallVector.h:274
const T * const_iterator
the iterator on the constant items
Definition SmallVector.h:138
const_iterator begin(void) const
the constant iterator on the first item
Definition SmallVector.h:276
const_iterator cend(void) const
the constant iterator past the last item
Definition SmallVector.h:282
iterator begin(void)
the iterator on the first item
Definition SmallVector.h:272
T * pointer
a pointer to an item
Definition SmallVector.h:132
SmallVector & operator=(SmallVector &&other)
the move assignment: the memory of other if its allocator propagates or is equal, else its items move...
Definition SmallVector.h:209
void resize(std::size_t n, const T &x=T())
items, those added made from
SmallVector(std::size_t n, const T &x=T())
items made from
void push_back(const T &x)
at the end, amortized; may be an item of the vector
Definition SmallVector.h:340
const_reverse_iterator rbegin(void) const
the constant iterator on the last item, backwards
Definition SmallVector.h:292
std::size_t size(void) const
the number of items,
Definition SmallVector.h:238
bool operator==(const SmallVector &o) const
the same items in the same order
Definition SmallVector.h:382
SmallVector & operator=(const SmallVector &other)
a copy of other
~SmallVector()
destroys the items, and frees the memory of the allocator if any
SmallVector(SmallVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
the items of other, which is left empty
SmallVector(std::initializer_list< T > items)
the vector of the given items, in their order
reverse_iterator rbegin(void)
the iterator on the last item, backwards
Definition SmallVector.h:284
allocator_type get_allocator(void) const
the allocator of the items
Definition SmallVector.h:219
T & operator[](std::size_t i)
the item at the index
Definition SmallVector.h:302
SmallVector(const SmallVector &other, const A &alloc)
a copy of other, on alloc
std::size_t capacity(void) const
the room, items, at least
Definition SmallVector.h:241
void push_back(T &&x)
at the end, moved, as push_back() above
Definition SmallVector.h:343
T value_type
the type of the items
Definition SmallVector.h:122
const T & operator[](std::size_t i) const
the item at the index , constant
Definition SmallVector.h:308
SmallVector(I first, S last)
the items of [ first , last ), in their order
std::reverse_iterator< iterator > reverse_iterator
the iterator on the items, backwards
Definition SmallVector.h:140
SmallVector(SmallVector &&other, const A &alloc)
the items of other, which is left empty, on alloc: its memory if the allocators are equal,...
void clear(void)
removes the items, keeping the memory
A allocator_type
the type of the allocator
Definition SmallVector.h:216
SmallVector & operator=(SmallVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
the items of other, which is left empty
T * data(void)
the vector of the items
Definition SmallVector.h:247
SmallVector(void) noexcept
the empty vector, its items inside it
Definition SmallVector.h:146
SmallVector(const A &alloc) noexcept
the empty vector, its items inside it, the allocator alloc
Definition SmallVector.h:153
const T & const_reference
a constant reference to an item
Definition SmallVector.h:130
const_iterator cbegin(void) const
the constant iterator on the first item
Definition SmallVector.h:280
void reserve(std::size_t n)
room for items
T & reference
a reference to an item
Definition SmallVector.h:128
const T * data(void) const
the vector of the items, constant
Definition SmallVector.h:249
std::size_t size_type
the type of the sizes
Definition SmallVector.h:124
const T & back(void) const
the last item, constant
Definition SmallVector.h:333
T & front(void)
the first item
Definition SmallVector.h:315
SmallVector & operator=(const SmallVector &other)
the copy assignment, with the allocator of other if it propagates
Definition SmallVector.h:196
bool small(void) const
the items are inside the vector
Definition SmallVector.h:244
const_reverse_iterator rend(void) const
the constant iterator before the first item, backwards
Definition SmallVector.h:296
void pop_back(void)
removes the last item
std::reverse_iterator< const_iterator > const_reverse_iterator
the iterator on the constant items, backwards
Definition SmallVector.h:142
SmallVector(const SmallVector &other)
a copy of other
SmallVector(const SmallVector &other)
a copy of other, on the allocator that select_on_container_copy_construction() gives
Definition SmallVector.h:176
T & back(void)
the last item
Definition SmallVector.h:327
const T * const_pointer
a constant pointer to an item
Definition SmallVector.h:134
T & emplace_back(Args &&... args)
an item made from the arguments at the end, which may refer to items of the vector,...
reverse_iterator rend(void)
the iterator before the first item, backwards
Definition SmallVector.h:288
const_iterator end(void) const
the constant iterator past the last item
Definition SmallVector.h:278
T * iterator
the iterator on the items
Definition SmallVector.h:136
#define ADS_PRE(cond)
[check]
Definition Contract.h:121