|
Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Implementation of a dynamic linear array storage, aka vector. More...
#include <darray.hpp>
Public Types | |
| typedef Value_type | value_type |
| typedef value_type * | pointer |
| typedef const value_type * | const_pointer |
| typedef value_type & | reference |
| typedef const value_type & | const_reference |
| typedef value_type * | iterator |
| typedef const value_type * | const_iterator |
| typedef Size_type | size_type |
| typedef std::make_signed< size_type >::type | difference_type |
| typedef Alloc_type | allocator_type |
| typedef bool | darray_tag |
| Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T> More... | |
| 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... | |
Public Member Functions | |
| constexpr | darray () noexcept |
| Default constructor, giving zero capacity and zero memory footprint. More... | |
| constexpr | 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 | darray (const darray &x) |
| Creates a new instance, copying all elements from the given darray. More... | |
| constexpr | darray (const darray &x, const float growth_factor, const allocator_type &alloc) |
| Creates a new instance, copying all elements from the given darray. More... | |
| constexpr | darray (const 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 darray. More... | |
| constexpr darray & | operator= (const darray &x) |
| Like std::vector::operator=(&), assignment. More... | |
| constexpr | darray (darray &&x) noexcept |
| constexpr | darray (darray &&x, const float growth_factor, const allocator_type &alloc) noexcept |
| constexpr darray & | operator= (darray &&x) noexcept |
| Like std::vector::operator=(&&), move. More... | |
| constexpr | 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 | 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... | |
| template<class InputIt > | |
| constexpr | 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 | darray (std::initializer_list< value_type > initlist, const allocator_type &alloc=allocator_type()) |
| Create a new instance from an initializer list. More... | |
| ~darray () noexcept | |
| constexpr size_type | max_size () const noexcept |
Returns std::numeric_limits<difference_type>::max() as the maximum array size. More... | |
| constexpr iterator | begin () noexcept |
| constexpr const_iterator | begin () const noexcept |
| constexpr const_iterator | cbegin () const noexcept |
| constexpr iterator | end () noexcept |
| constexpr const_iterator | end () const noexcept |
| constexpr const_iterator | cend () const noexcept |
| const allocator_type & | get_allocator_ref () const noexcept |
| allocator_type | get_allocator () const noexcept |
| constexpr float | growth_factor () const noexcept |
| constexpr size_type | capacity () const noexcept |
| Return the current capacity. More... | |
| constexpr size_type | get_grown_capacity () const noexcept |
| Return the current capacity() multiplied by the growth factor, minimum is max(capacity()+1, 10). More... | |
| constexpr bool | empty () const noexcept |
| Like std::vector::empty(). More... | |
| constexpr bool | capacity_reached () const noexcept |
| Returns true if capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references. More... | |
| constexpr size_type | size () const noexcept |
| Like std::vector::size(). More... | |
| constexpr reference | front () |
| Like std::vector::front(), mutable access. More... | |
| constexpr const_reference | front () const |
| Like std::vector::front(), immutable access. More... | |
| constexpr reference | back () |
| Like std::vector::back(), mutable access. More... | |
| constexpr const_reference | back () const |
| Like std::vector::back(), immutable access. More... | |
| constexpr const_pointer | data () const noexcept |
| Like std::vector::data(), const immutable pointer. More... | |
| constexpr pointer | data () noexcept |
| Like std::vector::data(), mutable pointer. More... | |
| const_reference | operator[] (size_type i) const noexcept |
| Like std::vector::operator[](size_type), immutable reference. More... | |
| reference | operator[] (size_type i) noexcept |
| Like std::vector::operator[](size_type), mutable reference. More... | |
| const_reference | at (size_type i) const |
| Like std::vector::at(size_type), immutable reference. More... | |
| reference | at (size_type i) |
| Like std::vector::at(size_type), mutable reference. More... | |
| void | reserve (size_type new_capacity) |
Like std::vector::reserve(), increases this instance's capacity to new_capacity. More... | |
| template<class InputIt > | |
| constexpr void | assign (InputIt first, InputIt last) |
| Like std::vector::assign() More... | |
| constexpr void | assign (const_iterator first, const_iterator last) |
| Like std::vector::assign(), but non-template overload using const_iterator. More... | |
| constexpr void | clear () noexcept |
| Like std::vector::clear(), but ending with zero capacity. More... | |
| constexpr void | swap (darray &x) noexcept |
| Like std::vector::swap(). More... | |
| constexpr void | pop_back () noexcept |
| Like std::vector::pop_back(). More... | |
| constexpr iterator | erase (const_iterator pos) |
| Like std::vector::erase(), removes the elements at pos. More... | |
| constexpr iterator | erase (iterator first, const_iterator last) |
| Like std::vector::erase(), removes the elements in the range [first, last). More... | |
| constexpr iterator | insert (const_iterator pos, const value_type &x) |
| Like std::vector::insert(), copy. More... | |
| constexpr iterator | insert (const_iterator pos, value_type &&x) |
| Like std::vector::insert(), move. More... | |
| template<typename... Args> | |
| constexpr iterator | emplace (const_iterator pos, Args &&... args) |
| Like std::vector::emplace(), construct a new element in place. More... | |
| template<class InputIt > | |
| constexpr iterator | insert (const_iterator pos, InputIt first, InputIt last) |
| Like std::vector::insert(), inserting the value_type range [first, last). More... | |
| constexpr void | push_back (const value_type &x) |
| Like std::vector::push_back(), copy. More... | |
| constexpr void | push_back (value_type &&x) |
| Like std::vector::push_back(), move. More... | |
| template<typename... Args> | |
| constexpr reference | emplace_back (Args &&... args) |
| Like std::vector::emplace_back(), construct a new element in place at the end(). More... | |
| template<class InputIt > | |
| constexpr void | push_back (InputIt first, InputIt last) |
| Like std::vector::push_back(), but appends the value_type range [first, last). More... | |
| constexpr 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... | |
| constexpr int | erase_matching (const value_type &x, const bool all_matching, equal_comparator comparator) |
| Erase either the first matching element or all matching elements. More... | |
| constexpr_cxx20 std::string | toString () const noexcept |
| constexpr_cxx20 std::string | get_info () const noexcept |
Static Public Attributes | |
| constexpr static const float | DEFAULT_GROWTH_FACTOR = 1.618f |
| Default growth factor using the golden ratio 1.618. More... | |
| constexpr static const bool | uses_memmove = use_memmove |
| constexpr static const bool | uses_realloc = use_realloc |
| constexpr static const bool | uses_secmem = sec_mem |
Implementation of a dynamic linear array storage, aka vector.
Goals are to support a high-performance CoW dynamic array implementation, jau::cow_darray,
exposing fine grained control over its underlying storage facility.
Further, jau::darray provides high-performance and efficient storage properties on its own.
This class shall be compliant with C++ named requirements for Container.
API and design differences to std::vector
Implementation differences to std::vector and some details
Non-Type Template Parameter use_memmove can be overriden by the user and has its default value std::is_trivially_copyable_v<Value_type>.
The default value has been chosen with care, see C++ Standard section 6.9 Types trivially copyable.
However, one can set use_memmove to true even without the value_type being trivially copyable, as long certain memory side-effects can be excluded (TBD).
Definition at line 101 of file darray.hpp.
| typedef Alloc_type jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::allocator_type |
Definition at line 124 of file darray.hpp.
| typedef const value_type* jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::const_iterator |
Definition at line 119 of file darray.hpp.
| typedef const value_type* jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::const_pointer |
Definition at line 115 of file darray.hpp.
| typedef const value_type& jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::const_reference |
Definition at line 117 of file darray.hpp.
| typedef bool jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::darray_tag |
Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T>
Definition at line 127 of file darray.hpp.
| typedef std::make_signed<size_type>::type jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::difference_type |
Definition at line 121 of file darray.hpp.
| typedef bool(* jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::equal_comparator) (const value_type &a, const value_type &b) |
Generic value_type equal comparator to be user defined for e.g.
jau::darray::push_back_unique().
| a | one element of the equality test. |
| b | the other element of the equality test. |
Definition at line 1055 of file darray.hpp.
| typedef value_type* jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::iterator |
Definition at line 118 of file darray.hpp.
| typedef value_type* jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::pointer |
Definition at line 114 of file darray.hpp.
| typedef value_type& jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::reference |
Definition at line 116 of file darray.hpp.
| typedef Size_type jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::size_type |
Definition at line 120 of file darray.hpp.
| typedef Value_type jau::darray< Value_type, Alloc_type, Size_type, use_memmove, use_realloc, sec_mem >::value_type |
Definition at line 113 of file darray.hpp.
|
inlineconstexprnoexcept |
Default constructor, giving zero capacity and zero memory footprint.
Definition at line 378 of file darray.hpp.
|
inlineexplicitconstexpr |
Creating an empty instance with initial capacity and other (default) properties.
| capacity | initial capacity of the new instance. |
| growth_factor | given growth factor |
| alloc | given allocator_type |
Definition at line 390 of file darray.hpp.
|
inlineconstexpr |
Creates a new instance, copying all elements from the given darray.
Capacity and size will equal the given array, i.e. the result is a trimmed jau::darray.
| x | the given darray, all elements will be copied into the new instance. |
Definition at line 403 of file darray.hpp.
|
inlineexplicitconstexpr |
Creates a new instance, copying all elements from the given darray.
Capacity and size will equal the given array, i.e. the result is a trimmed jau::darray.
| x | the given darray, all elements will be copied into the new instance. |
| growth_factor | custom growth factor |
| alloc | custom allocator_type instance |
Definition at line 417 of file darray.hpp.
|
inlineexplicitconstexpr |
Creates a new instance with custom initial storage capacity, copying all elements from the given darray.
Size will equal the given array.
Throws jau::IllegalArgumentException() if _capacity < x.size().
| x | the given darray, all elements will be copied into the new instance. |
| _capacity | custom initial storage capacity |
| growth_factor | custom growth factor |
| alloc | custom allocator_type instance |
Definition at line 435 of file darray.hpp.
|
inlineconstexprnoexcept |
Definition at line 469 of file darray.hpp.
|
inlineexplicitconstexprnoexcept |
Definition at line 479 of file darray.hpp.
|
inlineexplicitconstexpr |
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).
| _capacity | custom initial storage capacity |
| first | const_iterator to first element of value_type range [first, last) |
| last | const_iterator to last element of value_type range [first, last) |
| growth_factor | custom growth factor |
| alloc | custom allocator_type instance |
Definition at line 533 of file darray.hpp.
|
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).
| InputIt | template input-iterator custom type |
| _capacity | custom initial storage capacity |
| first | template input-iterator to first element of value_type range [first, last) |
| last | template input-iterator to last element of value_type range [first, last) |
| growth_factor | custom growth factor |
| alloc | custom allocator_type instance |
Definition at line 555 of file darray.hpp.
|
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).
| InputIt | template input-iterator custom type |
| first | template input-iterator to first element of value_type range [first, last) |
| last | template input-iterator to last element of value_type range [first, last) |
| alloc | custom allocator_type instance |
Definition at line 572 of file darray.hpp.
|
inlineconstexpr |
Create a new instance from an initializer list.
| initlist | initializer_list. |
| alloc | allocator |
Definition at line 584 of file darray.hpp.
|
inlinenoexcept |
Definition at line 590 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::assign(), but non-template overload using const_iterator.
| first | first const_iterator to range of value_type [first, last) |
| last | last const_iterator to range of value_type [first, last) |
Definition at line 778 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::assign()
| InputIt | foreign input-iterator to range of value_type [first, last) |
| first | first foreign input-iterator to range of value_type [first, last) |
| last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 759 of file darray.hpp.
|
inline |
Like std::vector::at(size_type), mutable reference.
Definition at line 729 of file darray.hpp.
|
inline |
Like std::vector::at(size_type), immutable reference.
Definition at line 719 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::back(), mutable access.
Definition at line 685 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::back(), immutable access.
Definition at line 690 of file darray.hpp.
|
inlineconstexprnoexcept |
Definition at line 608 of file darray.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Return the current capacity.
Definition at line 643 of file darray.hpp.
|
inlineconstexprnoexcept |
Returns true if capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references.
Definition at line 663 of file darray.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Like std::vector::clear(), but ending with zero capacity.
Definition at line 796 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::data(), const immutable pointer.
Definition at line 695 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::data(), mutable pointer.
Definition at line 700 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::emplace(), construct a new element in place.
Constructs the element before the given position using placement new and moves all elements from there to the right beforehand.
size will be increased by one.
| pos | iterator before which the content will be inserted. pos may be the end() iterator |
| args | arguments to forward to the constructor of the element |
Definition at line 937 of file darray.hpp.
|
inlineconstexpr |
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.
| args | arguments to forward to the constructor of the element |
Definition at line 1022 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::empty().
Definition at line 657 of file darray.hpp.
|
inlineconstexprnoexcept |
Definition at line 614 of file darray.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexpr |
Like std::vector::erase(), removes the elements at pos.
Definition at line 832 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::erase(), removes the elements in the range [first, last).
Definition at line 848 of file darray.hpp.
|
inlineconstexpr |
Erase either the first matching element or all matching elements.
Examples
darray<Thing> list;
int count = list.erase_matching(element, true,
[](const Thing &a, const Thing &b) -> bool { return a == b; });
...
static jau::darray<Thing>::equal_comparator thingRefEqComparator =
[](const std::shared_ptr<Thing> &a, const std::shared_ptr<Thing> &b) -> bool { return *a == *b; };
...
darray<std::shared_ptr<Thing>> listOfRefs;
int count = listOfRefs.erase_matching(element, false, thingRefEqComparator);
| x | the value to be added at the tail, if not existing yet. |
| all_matching | if true, erase all matching elements, otherwise only the first matching element. |
| comparator | the equal comparator to return true if both given elements are equal |
Definition at line 1111 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::front(), mutable access.
Definition at line 675 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::front(), immutable access.
Definition at line 680 of file darray.hpp.
|
inlinenoexcept |
Definition at line 632 of file darray.hpp.
|
inlinenoexcept |
Definition at line 628 of file darray.hpp.
|
inlineconstexprnoexcept |
Return the current capacity() multiplied by the growth factor, minimum is max(capacity()+1, 10).
Definition at line 648 of file darray.hpp.
|
inlinenoexcept |
|
inlineconstexprnoexcept |
Definition at line 636 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::insert(), copy.
Inserts the element before pos and moves all elements from there to the right beforehand.
size will be increased by one.
| pos | iterator before which the content will be inserted. pos may be the end() iterator |
| x | element value to insert |
Definition at line 872 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::insert(), inserting the value_type range [first, last).
| InputIt | foreign input-iterator to range of value_type [first, last) |
| pos | iterator before which the content will be inserted. pos may be the end() iterator |
| first | first foreign input-iterator to range of value_type [first, last) |
| last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 966 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::insert(), move.
Inserts the element before the given position and moves all elements from there to the right beforehand.
size will be increased by one.
| pos | iterator before which the content will be inserted. pos may be the end() iterator |
| x | element value to be moved into |
Definition at line 904 of file darray.hpp.
|
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 602 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::operator=(&), assignment.
Definition at line 445 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::operator=(&&), move.
Definition at line 499 of file darray.hpp.
|
inlinenoexcept |
Like std::vector::operator[](size_type), immutable reference.
Definition at line 705 of file darray.hpp.
|
inlinenoexcept |
Like std::vector::operator[](size_type), mutable reference.
Definition at line 712 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::pop_back().
Definition at line 822 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), copy.
| x | the value to be added at the tail. |
Definition at line 991 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), but appends the value_type range [first, last).
| InputIt | foreign input-iterator to range of value_type [first, last) |
| first | first foreign input-iterator to range of value_type [first, last) |
| last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 1039 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), move.
| x | the value to be added at the tail. |
Definition at line 1003 of file darray.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), but only if the newly added element does not yet exist.
Examples
static jau::darray<Thing>::equal_comparator thingEqComparator =
[](const Thing &a, const Thing &b) -> bool { return a == b; };
...
jau::darray<Thing> list; bool added = list.push_back_unique(new_element, thingEqComparator);
...
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; });
| x | the value to be added at the tail, if not existing yet. |
| comparator | the equal comparator to return true if both given elements are equal |
Definition at line 1078 of file darray.hpp.
|
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().
Definition at line 745 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::size().
Definition at line 668 of file darray.hpp.
|
inlineconstexprnoexcept |
Like std::vector::swap().
Definition at line 807 of file darray.hpp.
|
inlinenoexcept |
|
staticconstexpr |
Default growth factor using the golden ratio 1.618.
Definition at line 105 of file darray.hpp.
|
staticconstexpr |
Definition at line 107 of file darray.hpp.
|
staticconstexpr |
Definition at line 108 of file darray.hpp.
|
staticconstexpr |
Definition at line 109 of file darray.hpp.
1.8.18