[#prevector-0c]
= prevector
:mrdocs:

Implements a drop&hyphen;in replacement for std&colon;&colon;vector&lt;T&gt; which stores up to N elements directly (without heap allocation)&period; The types Size and Diff are used to store element counts, and can be any unsigned &plus; signed type&period;

== Synopsis

Declared in `&lt;prevector&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    unsigned int N,
    typename T,
    typename Size = uint32&lowbar;t,
    typename Diff = int32&lowbar;t&gt;
class prevector;
----

== Description

Storage layout is either&colon;

* Direct allocation&colon;
* Size &lowbar;size&colon; the number of used elements (between 0 and N)
* T direct&lsqb;N&rsqb;&colon; an array of N elements of type T (only the first &lowbar;size are initialized)&period;
* Indirect allocation&colon;
* Size &lowbar;size&colon; the number of used elements plus N &plus; 1
* Size capacity&colon; the number of allocated elements
* T&ast; indirect&colon; a pointer to an array of capacity elements of type T (only the first &lowbar;size are initialized)&period;

The data type T must be movable by memmove&sol;realloc()&period; Once we switch to C&plus;&plus;, move constructors can be used instead&period;

== Types

[cols="1,4"]
|===
| Name| Description
| xref:prevector-0c/const_iterator.adoc[`const&lowbar;iterator`] 
| Read&hyphen;only contiguous iterator over the container&apos;s elements&period;
| xref:prevector-0c/iterator.adoc[`iterator`] 
| Mutable contiguous iterator over the container&apos;s elements&period;
|===


== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:prevector-0c/const_pointer.adoc[`const&lowbar;pointer`] 
| Pointer to a const element&period;
| xref:prevector-0c/const_reference.adoc[`const&lowbar;reference`] 
| Reference to a const element&period;
| xref:prevector-0c/difference_type.adoc[`difference&lowbar;type`] 
| Signed type used to represent distances between iterators&period;
| xref:prevector-0c/pointer.adoc[`pointer`] 
| Pointer to an element&period;
| xref:prevector-0c/reference.adoc[`reference`] 
| Reference to an element&period;
| xref:prevector-0c/size_type.adoc[`size&lowbar;type`] 
| Unsigned type used to store element counts&period;
| xref:prevector-0c/value_type.adoc[`value&lowbar;type`] 
| Type of the elements held by the container&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:prevector-0c/2constructor-0e.adoc[`prevector`]         [.small]#[constructor]#
| Constructors
| xref:prevector-0c/2destructor.adoc[`&#126;prevector`] [.small]#[destructor]#
| Destroys the container, freeing any heap allocation&period;
| xref:prevector-0c/operator_assign-0e.adoc[`operator&equals;`] 
| Assignment operators
| xref:prevector-0c/allocated_memory.adoc[`allocated&lowbar;memory`] 
| Returns the number of bytes held in the heap allocation, or zero when stored inline&period;
| xref:prevector-0c/assign-084.adoc[`assign`] 
| `assign` overloads
| xref:prevector-0c/back-0a.adoc[`back`] 
| `back` overloads
| xref:prevector-0c/begin-0d.adoc[`begin`] 
| `begin` overloads
| xref:prevector-0c/capacity.adoc[`capacity`] 
| Returns the number of elements the container can hold without reallocating&period;
| xref:prevector-0c/clear.adoc[`clear`] 
| Removes all elements, leaving the container empty&period;
| xref:prevector-0c/data-0e.adoc[`data`] 
| `data` overloads
| xref:prevector-0c/emplace_back.adoc[`emplace&lowbar;back`] 
| Constructs a new element in place at the end of the container&period;
| xref:prevector-0c/empty.adoc[`empty`] 
| Returns whether the container holds no elements&period;
| xref:prevector-0c/end-0d.adoc[`end`] 
| `end` overloads
| xref:prevector-0c/erase-03.adoc[`erase`] 
| `erase` overloads
| xref:prevector-0c/front-0cf.adoc[`front`] 
| `front` overloads
| xref:prevector-0c/insert-0c.adoc[`insert`] 
| `insert` overloads
| xref:prevector-0c/operator_subs-08.adoc[`operator&lsqb;&rsqb;`] 
| Subscript operators
| xref:prevector-0c/pop_back.adoc[`pop&lowbar;back`] 
| Removes the last element&period;
| xref:prevector-0c/push_back.adoc[`push&lowbar;back`] 
| Appends a copy of `value` to the end of the container&period;
| xref:prevector-0c/reserve.adoc[`reserve`] 
| Ensures capacity for at least `new&lowbar;capacity` elements without changing the size&period;
| xref:prevector-0c/resize.adoc[`resize`] 
| Resizes the container to hold `new&lowbar;size` elements, value&hyphen;initializing any new ones&period;
| xref:prevector-0c/resize_uninitialized.adoc[`resize&lowbar;uninitialized`] 
| Changes the size to `new&lowbar;size` without initializing any newly added elements&period;
| xref:prevector-0c/shrink_to_fit.adoc[`shrink&lowbar;to&lowbar;fit`] 
| Reduces the capacity to match the current size&period;
| xref:prevector-0c/size.adoc[`size`] 
| Returns the number of elements currently stored&period;
| xref:prevector-0c/swap.adoc[`swap`] 
| Exchanges the contents of this container with `other`&period;
| xref:prevector-0c/operator_eq.adoc[`operator&equals;&equals;`] 
| Returns whether this container holds the same elements as `other`&period;
| xref:prevector-0c/operator_lt.adoc[`operator&lt;`] 
| Orders two containers lexicographically by their elements&period;
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:prevector-0c/STATIC_SIZE.adoc[`STATIC&lowbar;SIZE`] 
| Number of elements stored inline before switching to heap allocation&period;
|===


== Specializations

[cols="1,4"]
|===
| Name| Description
| xref:prevector-01.adoc[`prevector&lt;36, unsigned char&gt;`] 
| Implements a drop&hyphen;in replacement for std&colon;&colon;vector&lt;T&gt; which stores up to N elements directly (without heap allocation)&period; The types Size and Diff are used to store element counts, and can be any unsigned &plus; signed type&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:memusage/DynamicUsage-084.adoc[`memusage&colon;&colon;DynamicUsage`]
| Dynamic memory used by a prevector&apos;s overflow buffer&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
