Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Public Types | Public Member Functions | Static Public Attributes | List of all members
jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > Class Template Reference

Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage, exposing lock-free read operations using SC-DRF atomic synchronization. More...

#include <cow_darray.hpp>

Inheritance diagram for jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >:
Collaboration diagram for jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >:

Public Types

typedef Alloc_type allocator_type
 
typedef cow_ro_iterator< storage_t, storage_ref_t, cow_container_tconst_iterator
 Immutable, read-only const_iterator, lock-free, holding the current shared store reference until destruction. More...
 
typedef const value_typeconst_pointer
 
typedef const value_typeconst_reference
 
typedef cow_darray< value_type, size_type, allocator_type, use_memmove, use_secmem > cow_container_t
 
typedef bool darray_tag
 Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T> More...
 
typedef std::make_signed< size_type >::type difference_type
 
typedef bool(* equal_comparator) (const value_type &a, const value_type &b)
 Generic value_type equal comparator to be user defined for e.g. More...
 
typedef cow_rw_iterator< storage_t, storage_ref_t, cow_container_titerator
 Mutable, read-write iterator, holding the write-lock and a store copy until destruction. More...
 
typedef value_typepointer
 
typedef value_typereference
 
typedef Size_type size_type
 
typedef std::shared_ptr< storage_tstorage_ref_t
 
typedef darray< value_type, size_type, allocator_type, use_memmove, use_secmem > storage_t
 
typedef Value_type value_type
 

Public Member Functions

constexpr cow_darray () noexcept
 Default constructor, giving almost zero capacity and zero memory footprint, but the shared empty jau::darray. More...
 
constexpr_atomic cow_darray (const cow_darray &x)
 Creates a new instance, copying all elements from the given array. More...
 
constexpr_atomic cow_darray (const cow_darray &x, const float growth_factor, const allocator_type &alloc)
 Creates a new instance, copying all elements from the given array. More...
 
constexpr_atomic cow_darray (const cow_darray &x, const size_type _capacity, const float growth_factor, const allocator_type &alloc)
 Creates a new instance with custom initial storage capacity, copying all elements from the given array. More...
 
constexpr cow_darray (const size_type _capacity, const_iterator first, const_iterator last, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type())
 Creates a new instance with custom initial storage capacity, copying all elements from the given const_iterator value_type range [first, last). More...
 
template<class InputIt >
constexpr cow_darray (const size_type _capacity, InputIt first, InputIt last, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type())
 Creates a new instance with custom initial storage capacity, copying all elements from the given template input-iterator value_type range [first, last). More...
 
constexpr cow_darray (const storage_t &x)
 
constexpr cow_darray (const storage_t &x, const float growth_factor, const allocator_type &alloc)
 
constexpr_atomic cow_darray (cow_darray &&x) noexcept
 
template<class InputIt >
constexpr cow_darray (InputIt first, InputIt last, const allocator_type &alloc=allocator_type())
 Creates a new instance, copying all elements from the given template input-iterator value_type range [first, last). More...
 
constexpr cow_darray (size_type capacity, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type())
 Creating an empty instance with initial capacity and other (default) properties. More...
 
constexpr cow_darray (std::initializer_list< value_type > initlist, const allocator_type &alloc=allocator_type())
 Using the std::initializer_list requires to copy the given value_type objects into this cow_darray. More...
 
constexpr cow_darray (storage_t &&x) noexcept
 
constexpr cow_darray (storage_t &&x, const float growth_factor, const allocator_type &alloc) noexcept
 
 ~cow_darray () noexcept
 
constexpr iterator begin ()
 Returns an jau::cow_rw_iterator to the first element of this CoW storage. More...
 
constexpr_atomic size_type capacity () const noexcept
 Like std::vector::empty(). More...
 
constexpr const_iterator cbegin () const noexcept
 Returns an jau::cow_ro_iterator to the first element of this CoW storage. More...
 
constexpr_atomic void clear () noexcept
 Like std::vector::clear(), but ending with zero capacity. More...
 
constexpr_atomic storage_ref_t copy_store ()
 Returns a new shared_ptr copy of the underlying store, i.e. More...
 
template<typename... Args>
constexpr_atomic reference emplace_back (Args &&... args)
 Like std::vector::emplace_back(), construct a new element in place at the end(). More...
 
constexpr_atomic bool empty () const noexcept
 Like std::vector::empty(). More...
 
constexpr_atomic size_type erase_matching (const value_type &x, const bool all_matching, equal_comparator comparator)
 Erase either the first matching element or all matching elements. More...
 
allocator_type get_allocator () const noexcept
 
const allocator_typeget_allocator_ref () const noexcept
 
std::string get_info () const noexcept
 
constexpr std::recursive_mutex & get_write_mutex () noexcept
 Returns this instances' recursive write mutex, allowing user to implement more complex mutable write operations. More...
 
constexpr_atomic float growth_factor () const noexcept
 Returns the growth factor. More...
 
constexpr size_type max_size () const noexcept
 Returns std::numeric_limits<difference_type>::max() as the maximum array size. More...
 
constexpr_atomic cow_darrayoperator= (const cow_darray &x)
 Like std::vector::operator=(&), assignment. More...
 
cow_darrayoperator= (const storage_t &x)
 Like std::vector::operator=(&), assignment, but copying from the underling jau::darray. More...
 
constexpr_atomic cow_darrayoperator= (cow_darray &&x) noexcept
 Like std::vector::operator=(&&), move. More...
 
cow_darrayoperator= (storage_t &&x)
 Like std::vector::operator=(&&), move, but taking the underling jau::darray. More...
 
constexpr_atomic void pop_back () noexcept
 Like std::vector::pop_back(). More...
 
constexpr_atomic void push_back (const value_type &x)
 Like std::vector::push_back(), copy. More...
 
template<class InputIt >
constexpr_atomic void push_back (InputIt first, InputIt last)
 Like std::vector::push_back(), but appends the whole value_type range [first, last). More...
 
constexpr_atomic void push_back (value_type &&x)
 Like std::vector::push_back(), move. More...
 
template<typename... Args>
constexpr_atomic void push_back_list (Args &&... args)
 Like push_back(), but for more multiple r-value references to move. More...
 
template<typename... Args>
constexpr_atomic void push_back_list (const Args &... args)
 Like push_back(), but for more multiple const r-value to copy. More...
 
constexpr_atomic bool push_back_unique (const value_type &x, equal_comparator comparator)
 Like std::vector::push_back(), but only if the newly added element does not yet exist. More...
 
void reserve (size_type new_capacity)
 Like std::vector::reserve(), increases this instance's capacity to new_capacity. More...
 
constexpr_atomic void set_store (storage_ref_t &&new_store_ref) noexcept
 Replace the current store with the given instance, potentially acquired via jau::cow_darray::copy_store() and mutated while holding the jau::cow_darray::get_write_mutex() lock. More...
 
constexpr_atomic size_type size () const noexcept
 Like std::vector::size(). More...
 
constexpr_atomic storage_ref_t snapshot () const noexcept
 Returns the current snapshot of the underlying shared storage by reference. More...
 
constexpr_atomic void swap (cow_darray &x) noexcept
 Like std::vector::swap(). More...
 
std::string toString () const noexcept
 

Static Public Attributes

static constexpr const float DEFAULT_GROWTH_FACTOR = 1.618f
 Default growth factor using the golden ratio 1.618. More...
 
static constexpr const bool uses_memmove = use_memmove
 
static constexpr const bool uses_realloc = use_memmove && std::is_base_of_v<jau::callocator<Value_type>, Alloc_type>
 
static constexpr const bool uses_secmem = use_secmem
 

Detailed Description

template<typename Value_type, typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
class jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >

Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage, exposing lock-free read operations using SC-DRF atomic synchronization.

This data structure is also supporting Concurrency.

This class shall be compliant with C++ named requirements for Container.

The store is owned using a shared reference to the data structure, allowing its replacement on Copy-On-Write (CoW).

Writing to the store utilizes a mutex lock to avoid data races on the instances' write operations only, leaving read operations lock-free.
Write operations replace the store reference with a new instance using jau::sc_atomic_critical to synchronize with read operations.

Reading from the store is lock-free and accesses the store reference using jau::sc_atomic_critical to synchronizing with write operations.

Immutable storage const_iterators are supported via jau::cow_ro_iterator, which are constructed lock-free.
jau::cow_ro_iterator holds a snapshot retrieved via jau::cow_darray::snapshot() until its destruction.

Mutable storage iterators are supported via jau::cow_rw_iterator, which holds a copy of this CoW storage and locks its write mutex until jau::cow_rw_iterator::write_back() or its destruction.
After completing all mutable operations but before this iterator's destruction, the user might want to write back this iterators' storage to this CoW using jau::cow_rw_iterator::write_back().

Both, jau::cow_ro_iterator and jau::cow_rw_iterator are harmonized to work with jau::darray::const_iterator and jau::darray::iterator for all iterator based operations.

Index operation via ::operator[](size_t) or ::at(size_t) are not supported, since they would be only valid if value_type itself is a std::shared_ptr and hence prohibit the destruction of the object if mutating the storage, e.g. via jau::cow_darray::push_back().

Custom mutable write operations are also supported via jau::cow_darray::get_write_mutex(), jau::cow_darray::copy_store() and jau::cow_darray::set_store().
See example in jau::cow_darray::set_store()

To allow data-race free operations using iterators from a potentially mutated CoW, only one cow_darray::begin() const_iterator or iterator should be retrieved from this CoW and all further operations shall use its jau::cow_ro_iterator::size(), jau::cow_ro_iterator::begin() and jau::cow_ro_iterator::end()

Non-Type Template Parameter controlling Value_type memory

See darray_ntt_params.

use_memmove

use_memmove see darray_memmove.

use_secmem

use_secmem see darray_secmem.

See also:

See also
jau::darray
darray_ntt_params
jau::cow_ro_iterator
jau::for_each_fidelity
jau::cow_rw_iterator
jau::cow_rw_iterator::write_back()
Examples
test_cow_iterator_01.cpp.

Definition at line 126 of file cow_darray.hpp.

Member Typedef Documentation

◆ value_type

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef Value_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::value_type

Definition at line 138 of file cow_darray.hpp.

◆ pointer

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef value_type* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::pointer

Definition at line 139 of file cow_darray.hpp.

◆ const_pointer

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef const value_type* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_pointer

Definition at line 140 of file cow_darray.hpp.

◆ reference

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef value_type& jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::reference

Definition at line 141 of file cow_darray.hpp.

◆ const_reference

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef const value_type& jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_reference

Definition at line 142 of file cow_darray.hpp.

◆ size_type

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef Size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::size_type

Definition at line 143 of file cow_darray.hpp.

◆ difference_type

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef std::make_signed<size_type>::type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::difference_type

Definition at line 144 of file cow_darray.hpp.

◆ allocator_type

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef Alloc_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::allocator_type

Definition at line 145 of file cow_darray.hpp.

◆ storage_t

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef darray<value_type, size_type, allocator_type, use_memmove, use_secmem> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::storage_t

Definition at line 149 of file cow_darray.hpp.

◆ storage_ref_t

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef std::shared_ptr<storage_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::storage_ref_t

Definition at line 150 of file cow_darray.hpp.

◆ darray_tag

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::darray_tag

Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T>

Definition at line 153 of file cow_darray.hpp.

◆ cow_container_t

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef cow_darray<value_type, size_type, allocator_type, use_memmove, use_secmem> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_container_t

Definition at line 157 of file cow_darray.hpp.

◆ const_iterator

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef cow_ro_iterator<storage_t, storage_ref_t, cow_container_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_iterator

Immutable, read-only const_iterator, lock-free, holding the current shared store reference until destruction.

Using jau::cow_darray::snapshot() at construction.

This iterator is the preferred choice if no mutations are made to the elements state itself, or all changes can be discarded after the iterator's destruction.
This avoids the costly mutex lock and storage copy of jau::cow_rw_iterator.
Also see jau::for_each_fidelity to iterate through in this good faith fashion.

See also
jau::cow_ro_iterator
jau::cow_ro_iterator::size()
jau::cow_ro_iterator::begin()
jau::cow_ro_iterator::end()
jau::for_each_fidelity
jau::cow_rw_iterator

Definition at line 178 of file cow_darray.hpp.

◆ iterator

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef cow_rw_iterator<storage_t, storage_ref_t, cow_container_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::iterator

Mutable, read-write iterator, holding the write-lock and a store copy until destruction.

Using jau::cow_darray::get_write_mutex(), jau::cow_darray::copy_store() at construction
and jau::cow_darray::set_store() at destruction.

Due to the costly nature of mutable CoW resource management, consider using jau::cow_ro_iterator if elements won't get mutated or any changes can be discarded.

See also
jau::cow_rw_iterator
jau::cow_rw_iterator::size()
jau::cow_rw_iterator::begin()
jau::cow_rw_iterator::end()
jau::cow_ro_iterator

Definition at line 197 of file cow_darray.hpp.

◆ equal_comparator

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
typedef bool(* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::equal_comparator) (const value_type &a, const value_type &b)

Generic value_type equal comparator to be user defined for e.g.

jau::cow_darray::push_back_unique().

Parameters
aone element of the equality test.
bthe other element of the equality test.
Returns
true if both are equal

Definition at line 989 of file cow_darray.hpp.

Constructor & Destructor Documentation

◆ cow_darray() [1/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( )
inlineconstexprnoexcept

Default constructor, giving almost zero capacity and zero memory footprint, but the shared empty jau::darray.

Definition at line 215 of file cow_darray.hpp.

◆ cow_darray() [2/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( size_type  capacity,
const float  growth_factor = DEFAULT_GROWTH_FACTOR,
const allocator_type alloc = allocator_type() 
)
inlineexplicitconstexpr

Creating an empty instance with initial capacity and other (default) properties.

Parameters
capacityinitial capacity of the new instance.
growth_factorgiven growth factor
allocgiven allocator_type

Definition at line 226 of file cow_darray.hpp.

◆ cow_darray() [3/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const storage_t x)
inlineconstexpr

Definition at line 233 of file cow_darray.hpp.

◆ cow_darray() [4/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const storage_t x,
const float  growth_factor,
const allocator_type alloc 
)
inlineexplicitconstexpr

Definition at line 239 of file cow_darray.hpp.

◆ cow_darray() [5/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( storage_t &&  x)
inlineconstexprnoexcept

Definition at line 262 of file cow_darray.hpp.

◆ cow_darray() [6/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( storage_t &&  x,
const float  growth_factor,
const allocator_type alloc 
)
inlineexplicitconstexprnoexcept

Definition at line 269 of file cow_darray.hpp.

◆ cow_darray() [7/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &  x)
inline

Creates a new instance, copying all elements from the given array.


Capacity and size will equal the given array, i.e. the result is a trimmed array.

Parameters
xthe given cow_darray, all elements will be copied into the new instance.

Definition at line 302 of file cow_darray.hpp.

◆ cow_darray() [8/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &  x,
const float  growth_factor,
const allocator_type alloc 
)
inlineexplicit

Creates a new instance, copying all elements from the given array.


Capacity and size will equal the given array, i.e. the result is a trimmed array.

Parameters
xthe given cow_darray, all elements will be copied into the new instance.
growth_factorcustom growth factor
alloccustom allocator_type instance

Definition at line 322 of file cow_darray.hpp.

◆ cow_darray() [9/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &  x,
const size_type  _capacity,
const float  growth_factor,
const allocator_type alloc 
)
inlineexplicit

Creates a new instance with custom initial storage capacity, copying all elements from the given array.


Size will equal the given array.

Throws jau::IllegalArgumentException() if _capacity < x.size().

Parameters
xthe given cow_darray, all elements will be copied into the new instance.
_capacitycustom initial storage capacity
growth_factorcustom growth factor
alloccustom allocator_type instance

Definition at line 346 of file cow_darray.hpp.

◆ cow_darray() [10/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &&  x)
inlinenoexcept

Definition at line 385 of file cow_darray.hpp.

◆ cow_darray() [11/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const size_type  _capacity,
const_iterator  first,
const_iterator  last,
const float  growth_factor = DEFAULT_GROWTH_FACTOR,
const allocator_type alloc = allocator_type() 
)
inlineconstexpr

Creates a new instance with custom initial storage capacity, copying all elements from the given const_iterator value_type range [first, last).


Size will equal the range [first, last), i.e. size_type(last-first).

Throws jau::IllegalArgumentException() if _capacity < size_type(last - first).

Parameters
_capacitycustom initial storage capacity
firstconst_iterator to first element of value_type range [first, last)
lastconst_iterator to last element of value_type range [first, last)
growth_factorcustom growth factor
alloccustom allocator_type instance

Definition at line 447 of file cow_darray.hpp.

◆ cow_darray() [12/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<class InputIt >
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( const size_type  _capacity,
InputIt  first,
InputIt  last,
const float  growth_factor = DEFAULT_GROWTH_FACTOR,
const allocator_type alloc = allocator_type() 
)
inlineexplicitconstexpr

Creates a new instance with custom initial storage capacity, copying all elements from the given template input-iterator value_type range [first, last).


Size will equal the range [first, last), i.e. size_type(last-first).

Throws jau::IllegalArgumentException() if _capacity < size_type(last - first).

Template Parameters
InputIttemplate input-iterator custom type
Parameters
_capacitycustom initial storage capacity
firsttemplate input-iterator to first element of value_type range [first, last)
lasttemplate input-iterator to last element of value_type range [first, last)
growth_factorcustom growth factor
alloccustom allocator_type instance

Definition at line 469 of file cow_darray.hpp.

◆ cow_darray() [13/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<class InputIt >
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( InputIt  first,
InputIt  last,
const allocator_type alloc = allocator_type() 
)
inlineconstexpr

Creates a new instance, copying all elements from the given template input-iterator value_type range [first, last).


Size will equal the range [first, last), i.e. size_type(last-first).

Template Parameters
InputIttemplate input-iterator custom type
Parameters
firsttemplate input-iterator to first element of value_type range [first, last)
lasttemplate input-iterator to last element of value_type range [first, last)
alloccustom allocator_type instance

Definition at line 486 of file cow_darray.hpp.

◆ cow_darray() [14/14]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_darray ( std::initializer_list< value_type initlist,
const allocator_type alloc = allocator_type() 
)
inlineconstexpr

Using the std::initializer_list requires to copy the given value_type objects into this cow_darray.

To utilize more efficient move semantics, see push_back_list() and jau::make_cow_darray().

Parameters
initlistinitializer_list.
allocallocator
See also
push_back_list()
jau::make_cow_darray()

Definition at line 502 of file cow_darray.hpp.

◆ ~cow_darray()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::~cow_darray ( )
inlinenoexcept

Definition at line 509 of file cow_darray.hpp.

Member Function Documentation

◆ operator=() [1/4]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
cow_darray & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::operator= ( const storage_t x)
inline

Like std::vector::operator=(&), assignment, but copying from the underling jau::darray.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 251 of file cow_darray.hpp.

◆ operator=() [2/4]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
cow_darray & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::operator= ( storage_t &&  x)
inline

Like std::vector::operator=(&&), move, but taking the underling jau::darray.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 282 of file cow_darray.hpp.

◆ operator=() [3/4]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic cow_darray & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::operator= ( const cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &  x)
inline

Like std::vector::operator=(&), assignment.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 365 of file cow_darray.hpp.

◆ operator=() [4/4]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic cow_darray & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::operator= ( cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &&  x)
inlinenoexcept

Like std::vector::operator=(&&), move.

This write operation uses a mutex lock and is blocking both cow_vector instance's write operations.

Definition at line 410 of file cow_darray.hpp.

◆ max_size()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::max_size ( ) const
inlineconstexprnoexcept

Returns std::numeric_limits<difference_type>::max() as the maximum array size.

We rely on the signed difference_type for pointer arithmetic, deducing ranges from iterator.

Definition at line 520 of file cow_darray.hpp.

◆ get_write_mutex()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr std::recursive_mutex & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::get_write_mutex ( )
inlineconstexprnoexcept

Returns this instances' recursive write mutex, allowing user to implement more complex mutable write operations.

See example in jau::cow_darray::set_store()

See also
jau::cow_darray::get_write_mutex()
jau::cow_darray::copy_store()
jau::cow_darray::set_store()

Definition at line 535 of file cow_darray.hpp.

◆ copy_store()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic storage_ref_t jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::copy_store ( )
inline

Returns a new shared_ptr copy of the underlying store, i.e.

using a new copy-constructed vectore.

See example in jau::cow_darray::set_store()

This special operation uses a mutex lock and is blocking this instances' write operations only.

See also
jau::cow_darray::get_write_mutex()
jau::cow_darray::copy_store()
jau::cow_darray::set_store()

Definition at line 551 of file cow_darray.hpp.

◆ set_store()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::set_store ( storage_ref_t &&  new_store_ref)
inlinenoexcept

Replace the current store with the given instance, potentially acquired via jau::cow_darray::copy_store() and mutated while holding the jau::cow_darray::get_write_mutex() lock.

This is a move operation, i.e. the given new_store_ref is invalid on the caller side after this operation.
User shall pass the store via std::move()

    cow_darray<std::shared_ptr<Thing>> list;
    ...
    {
        std::lock_guard<std::recursive_mutex> lock(list.get_write_mutex());
        std::shared_ptr<std::vector<std::shared_ptr<Thing>>> snapshot = list.copy_store();
        ...
        some fancy mutation
        ...
        list.set_store(std::move(snapshot));
    }

Above functionality is covered by jau::cow_rw_iterator, see also jau::cow_rw_iterator::write_back()

Parameters
new_store_refthe user store to be moved here, replacing the current store.
See also
jau::cow_darray::get_write_mutex()
jau::cow_darray::copy_store()
jau::cow_darray::set_store()
jau::cow_rw_iterator
jau::cow_rw_iterator::write_back()

Definition at line 588 of file cow_darray.hpp.

◆ snapshot()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic storage_ref_t jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::snapshot ( ) const
inlinenoexcept

Returns the current snapshot of the underlying shared storage by reference.

Note that this snapshot will be outdated by the next (concurrent) write operation.
The returned referenced vector is still valid and not mutated, but does not represent the current content of this cow_darray instance.

This read operation is lock-free.

Definition at line 611 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ cbegin()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr const_iterator jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cbegin ( ) const
inlineconstexprnoexcept

Returns an jau::cow_ro_iterator to the first element of this CoW storage.

This method is the preferred choice if the use case allows, read remarks in jau::cow_ro_iterator.

Use jau::cow_ro_iterator::end() on this returned const_iterator to retrieve the end const_iterator in a data-race free fashion.

Returns
jau::cow_darray::const_iterator of type jau::cow_ro_iterator
See also
jau::cow_ro_iterator
jau::cow_ro_iterator::size()
jau::cow_ro_iterator::begin()
jau::cow_ro_iterator::end()
jau::for_each_fidelity

Definition at line 637 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ begin()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr iterator jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::begin ( )
inlineconstexpr

Returns an jau::cow_rw_iterator to the first element of this CoW storage.

Acquiring this mutable iterator has considerable costs attached, read remarks in jau::cow_rw_iterator.

Use jau::cow_rw_iterator::end() on this returned iterator to retrieve the end iterator in a data-race free fashion.

Returns
jau::cow_darray::iterator of type jau::cow_rw_iterator
See also
jau::cow_rw_iterator
jau::cow_rw_iterator::size()
jau::cow_rw_iterator::begin()
jau::cow_rw_iterator::end()

Definition at line 660 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ get_allocator_ref()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
const allocator_type & jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::get_allocator_ref ( ) const
inlinenoexcept

Definition at line 666 of file cow_darray.hpp.

◆ get_allocator()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
allocator_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::get_allocator ( ) const
inlinenoexcept

Definition at line 671 of file cow_darray.hpp.

◆ growth_factor()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic float jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::growth_factor ( ) const
inlinenoexcept

Returns the growth factor.

Definition at line 680 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ capacity()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::capacity ( ) const
inlinenoexcept

Like std::vector::empty().

This read operation is lock-free.

Returns

Definition at line 693 of file cow_darray.hpp.

◆ empty()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::empty ( ) const
inlinenoexcept

Like std::vector::empty().

This read operation is lock-free.

Definition at line 705 of file cow_darray.hpp.

◆ size()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::size ( ) const
inlinenoexcept

Like std::vector::size().

This read operation is lock-free.

Definition at line 717 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ reserve()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::reserve ( size_type  new_capacity)
inline

Like std::vector::reserve(), increases this instance's capacity to new_capacity.

Only creates a new storage and invalidates iterators if new_capacity is greater than the current jau::darray::capacity().

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 734 of file cow_darray.hpp.

◆ clear()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::clear ( )
inlinenoexcept

Like std::vector::clear(), but ending with zero capacity.

This write operation uses a mutex lock and is blocking this instances' write operations.

Definition at line 752 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ swap()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::swap ( cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem > &  x)
inlinenoexcept

Like std::vector::swap().

This write operation uses a mutex lock and is blocking both cow_darray instance's write operations.

Definition at line 768 of file cow_darray.hpp.

◆ pop_back()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::pop_back ( )
inlinenoexcept

Like std::vector::pop_back().

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 788 of file cow_darray.hpp.

◆ push_back() [1/3]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back ( const value_type x)
inline

Like std::vector::push_back(), copy.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Parameters
xthe value to be added at the tail.

Definition at line 811 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ push_back() [2/3]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back ( value_type &&  x)
inline

Like std::vector::push_back(), move.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Definition at line 836 of file cow_darray.hpp.

◆ emplace_back()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<typename... Args>
constexpr_atomic reference jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::emplace_back ( Args &&...  args)
inline

Like std::vector::emplace_back(), construct a new element in place at the end().

Constructs the element at the end() using placement new.

size will be increased by one.

Parameters
argsarguments to forward to the constructor of the element

Definition at line 866 of file cow_darray.hpp.

◆ push_back() [3/3]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<class InputIt >
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back ( InputIt  first,
InputIt  last 
)
inline

Like std::vector::push_back(), but appends the whole value_type range [first, last).

This write operation uses a mutex lock and is blocking this instances' write operations only.

Template Parameters
InputItforeign input-iterator to range of value_type [first, last)
Parameters
firstfirst foreign input-iterator to range of value_type [first, last)
lastlast foreign input-iterator to range of value_type [first, last)

Definition at line 896 of file cow_darray.hpp.

◆ push_back_list() [1/2]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<typename... Args>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back_list ( const Args &...  args)
inline

Like push_back(), but for more multiple const r-value to copy.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Template Parameters
Args
Parameters
argsr-value references to copy into this storage

Definition at line 926 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ push_back_list() [2/2]

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
template<typename... Args>
constexpr_atomic void jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back_list ( Args &&...  args)
inline

Like push_back(), but for more multiple r-value references to move.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Template Parameters
Args
Parameters
argsr-value references to move into this storage
See also
jau::make_cow_darray()

Definition at line 960 of file cow_darray.hpp.

◆ push_back_unique()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::push_back_unique ( const value_type x,
equal_comparator  comparator 
)
inline

Like std::vector::push_back(), but only if the newly added element does not yet exist.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Examples

    static jau::cow_darray<Thing>::equal_comparator thingEqComparator =
                 [](const Thing &a, const Thing &b) -> bool { return a == b; };
    ...
    jau::cow_darray<Thing> list;

    bool added = list.push_back_unique(new_element, thingEqComparator);
    ...
    cow_darray<std::shared_ptr<Thing>> listOfRefs;
    bool added = listOfRefs.push_back_unique(new_element,
                   [](const std::shared_ptr<Thing> &a, const std::shared_ptr<Thing> &b) -> bool { return *a == *b; });
Parameters
xthe value to be added at the tail, if not existing yet.
comparatorthe equal comparator to return true if both given elements are equal
Returns
true if the element has been uniquely added, otherwise false

Definition at line 1016 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ erase_matching()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr_atomic size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::erase_matching ( const value_type x,
const bool  all_matching,
equal_comparator  comparator 
)
inline

Erase either the first matching element or all matching elements.

This write operation uses a mutex lock and is blocking this instances' write operations only.

Examples

    cow_darray<Thing> list;
    int count = list.erase_matching(element, true,
                   [](const Thing &a, const Thing &b) -> bool { return a == b; });
    ...
    static jau::cow_darray<Thing>::equal_comparator thingRefEqComparator =
                 [](const std::shared_ptr<Thing> &a, const std::shared_ptr<Thing> &b) -> bool { return *a == *b; };
    ...
    cow_darray<std::shared_ptr<Thing>> listOfRefs;
    int count = listOfRefs.erase_matching(element, false, thingRefEqComparator);
Parameters
xthe value to be added at the tail, if not existing yet.
all_matchingif true, erase all matching elements, otherwise only the first matching element.
comparatorthe equal comparator to return true if both given elements are equal
Returns
number of erased elements

Definition at line 1054 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ toString()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
std::string jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::toString ( ) const
inlinenoexcept

Definition at line 1075 of file cow_darray.hpp.

Here is the caller graph for this function:

◆ get_info()

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
std::string jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::get_info ( ) const
inlinenoexcept

Definition at line 1086 of file cow_darray.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ DEFAULT_GROWTH_FACTOR

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr const float jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::DEFAULT_GROWTH_FACTOR = 1.618f
staticconstexpr

Default growth factor using the golden ratio 1.618.

Definition at line 130 of file cow_darray.hpp.

◆ uses_memmove

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr const bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::uses_memmove = use_memmove
staticconstexpr

Definition at line 132 of file cow_darray.hpp.

◆ uses_secmem

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr const bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::uses_secmem = use_secmem
staticconstexpr

Definition at line 133 of file cow_darray.hpp.

◆ uses_realloc

template<typename Value_type , typename Size_type = jau::nsize_t, typename Alloc_type = jau::callocator<Value_type>, bool use_memmove = std::is_trivially_copyable_v<Value_type> || is_container_memmove_compliant_v<Value_type>, bool use_secmem = is_enforcing_secmem_v<Value_type>>
constexpr const bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::uses_realloc = use_memmove && std::is_base_of_v<jau::callocator<Value_type>, Alloc_type>
staticconstexpr

Definition at line 134 of file cow_darray.hpp.


The documentation for this class was generated from the following file: