Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/inplace vector"

From cppreference.com
< cpp‎ | container
m (rm duplication.)
m (+more intro info, +#External links.)
Line 7: Line 7:
 
> struct inplace_vector;
 
> struct inplace_vector;
 
}}
 
}}
 +
 +
{{tt|inplace_vector}} is a dynamically-resizable array with contiguous inplace storage (that is, the elements of type {{tt|T}} are stored within the object itself) and with fixed at compile-time capacity {{tt|N}}.
 +
 +
{{tt|inplace_vector}} is useful in environments where dynamic memory allocations are undesired.
  
 
<!--DONE-->
 
<!--DONE-->
Line 35: Line 39:
 
{{par begin}}
 
{{par begin}}
 
{{par|T|element type.<!--Must be a complete object type that is not an abstract class type.--> Must be {{named req|MoveConstructible}} and {{named req|MoveAssignable}}.}}
 
{{par|T|element type.<!--Must be a complete object type that is not an abstract class type.--> Must be {{named req|MoveConstructible}} and {{named req|MoveAssignable}}.}}
{{par|N|the maximum number of elements in the {{tt|inplace_vector}} (might be {{c|0}}).}}
+
{{par|N|capacity, i.e. the maximum number of elements in the {{tt|inplace_vector}} (might be {{c|0}}).}}
 
{{par end}}
 
{{par end}}
 
{{todo|Complete the descriptions of template parameters.}}
 
{{todo|Complete the descriptions of template parameters.}}
Line 138: Line 142:
 
{{dsc inc|cpp/container/dsc deque}}
 
{{dsc inc|cpp/container/dsc deque}}
 
{{dsc end}}
 
{{dsc end}}
 +
 +
===External links===
 +
{{elink begin}}
 +
{{elink|[http://www.boost.org/doc/libs/1_59_0/doc/html/boost/container/static_vector.html Boost.Container: {{tt|static_vector}}] implements inplace vector as a standalone type with its own guarantees.}}
 +
{{elink|[https://github.com/questor/eastl/blob/master/fixed_vector.h#L71 EASTL: {{tt|fixed_vector}}] implements inplace vector via an extra template parameter.}}
 +
{{elink|[https://github.com/facebook/folly/blob/master/folly/docs/small_vector.md Folly: {{tt|small_vector}}] also implements inplace vector via an extra template parameter.}}
 +
{{elink|[https://godbolt.org/z/5P78aG5xE Compiler Explorer] &mdash; A reference implementation of {{stddoc|P0843R14}} ({{tt|std::inplace_vector}}).}}
 +
{{elink|}}
 +
{{elink end}}
  
 
{{langlinks|de|es|fr|it|ja|pl|pt|ru|zh}}
 
{{langlinks|de|es|fr|it|ja|pl|pt|ru|zh}}

Revision as of 22:37, 7 August 2024

 
 
 
 
Defined in header <inplace_vector>
template<

    class T,
    std::size_t N

> struct inplace_vector;
(since C++26)

inplace_vector is a dynamically-resizable array with contiguous inplace storage (that is, the elements of type T are stored within the object itself) and with fixed at compile-time capacity N.

inplace_vector is useful in environments where dynamic memory allocations are undesired.

Contents

Iterator invalidation

Template parameters

T - element type. Must be MoveConstructible and MoveAssignable.
N - capacity, i.e. the maximum number of elements in the inplace_vector (might be 0).

Member types

Member type Definition
value_type T[edit]
size_type std::size_t[edit]
difference_type std::ptrdiff_t[edit]
reference value_type&[edit]
const_reference const value_type&[edit]
pointer value_type*[edit]
const_pointer const value_type*[edit]
iterator implementation-defined LegacyRandomAccessIterator and random_access_iterator to value_type[edit]
const_iterator implementation-defined LegacyRandomAccessIterator and random_access_iterator to const value_type[edit]
reverse_iterator std::reverse_iterator<iterator>[edit]
const_reverse_iterator std::reverse_iterator<const_iterator>[edit]

Member functions

constructs the inplace_vector
(public member function) [edit]
destructs the inplace_vector
(public member function) [edit]
assigns values to the container
(public member function) [edit]
assigns values to the container
(public member function) [edit]
assigns a range of values to the container
(public member function) [edit]
Element access
access specified element with bounds checking
(public member function) [edit]
access specified element
(public member function) [edit]
access the first element
(public member function) [edit]
access the last element
(public member function) [edit]
direct access to the underlying contiguous storage
(public member function) [edit]
Iterators
returns an iterator to the beginning
(public member function) [edit]
returns an iterator to the end
(public member function) [edit]
returns a reverse iterator to the beginning
(public member function) [edit]
returns a reverse iterator to the end
(public member function) [edit]
Size and capacity
checks whether the container is empty
(public member function) [edit]
returns the number of elements
(public member function) [edit]
[static]
returns the maximum possible number of elements
(public static member function) [edit]
[static]
returns the number of elements that can be held in currently allocated storage
(public static member function) [edit]
changes the number of elements stored
(public member function) [edit]
[static]
reserves storage
(public static member function) [edit]
reduces memory usage by freeing unused memory
(public static member function) [edit]
Modifiers
inserts elements
(public member function) [edit]
inserts a range of elements
(public member function) [edit]
constructs element in-place
(public member function) [edit]
constructs an element in-place at the end
(public member function) [edit]
tries to construct an element in-place at the end
(public member function) [edit]
unconditionally constructs an element in-place at the end
(public member function) [edit]
adds an element to the end
(public member function) [edit]
tries to add an element to the end
(public member function) [edit]
unconditionally adds an element to the end
(public member function) [edit]
removes the last element
(public member function) [edit]
adds a range of elements to the end
(public member function) [edit]
tries to add a range of elements to the end
(public member function) [edit]
changes the number of elements stored
(public member function) [edit]
clears the contents
(public member function) [edit]
erases elements
(public member function) [edit]
swaps the contents
(public member function) [edit]

Non-member functions

specializes the std::swap algorithm
(function template) [edit]
erases all elements satisfying specific criteria
(function template) [edit]
lexicographically compares the values of two inplace_vectors
(function template) [edit]

Notes

Feature-test macro Value Std Feature
__cpp_lib_inplace_vector 202406L (C++26) std::inplace_vector: dynamically-resizable vector with fixed capacity inplace storage

Example

See also

dynamic contiguous array
(class template) [edit]
(C++11)
fixed-sized inplace contiguous array
(class template) [edit]
double-ended queue
(class template) [edit]

External links

  Boost.Container: static_vector implements inplace vector as a standalone type with its own guarantees.
  EASTL: fixed_vector implements inplace vector via an extra template parameter.
  Folly: small_vector also implements inplace vector via an extra template parameter.
  Compiler Explorer — A reference implementation of P0843R14 (std::inplace_vector).