4#ifndef TETL_VECTOR_VECTOR_HPP
5#define TETL_VECTOR_VECTOR_HPP
7#include <etl/_cstddef/ptrdiff_t.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_iterator/next.hpp>
10#include <etl/_memory/allocator_traits.hpp>
11#include <etl/_memory/ranges_destroy.hpp>
12#include <etl/_memory/uninitialized_fill.hpp>
13#include <etl/_utility/exchange.hpp>
14#include <etl/_utility/move.hpp>
15#include <etl/_utility/swap.hpp>
21template <
typename T,
typename Allocator>
24 using allocator_type = Allocator;
25 using size_type =
etl::size_t;
26 using difference_type =
etl::ptrdiff_t;
28 using const_pointer = T
const*;
30 using const_reference = T
const&;
32 using const_iterator = T
const*;
36 explicit constexpr vector(Allocator alloc)
37 : _alloc{
etl::move(alloc)}
41 constexpr vector(
etl::size_t n, T
const& value, Allocator alloc = Allocator())
42 : _alloc{
etl::move(alloc)}
44 allocate_and_fill(n, value);
47 explicit constexpr vector(
etl::size_t n, Allocator alloc = Allocator())
56 : _ptr{
etl::exchange(other._ptr,
nullptr)}
57 , _size{
etl::exchange(other._size,
etl::size_t(0))}
58 , _capacity{
etl::exchange(other._capacity,
etl::size_t(0))}
59 , _alloc{
etl::exchange(other._alloc, Allocator{})}
65 _ptr =
etl::exchange(other._ptr,
nullptr);
66 _size =
etl::exchange(other._size,
etl::size_t(0));
67 _capacity =
etl::exchange(other._capacity,
etl::size_t(0));
68 _alloc =
etl::exchange(other._alloc, Allocator{});
75 if (_ptr !=
nullptr) {
102 return etl::next(_ptr,
etl::ptrdiff_t(size()));
107 return etl::next(_ptr,
etl::ptrdiff_t(size()));
140 constexpr auto clear()
noexcept ->
void
148 etl::swap(lhs._ptr, rhs._ptr);
149 etl::swap(lhs._size, rhs._size);
150 etl::swap(lhs._capacity, rhs._capacity);
151 swap(lhs._alloc, rhs._alloc);
155 constexpr auto allocate_and_fill(
etl::size_t n, T
const& value) ->
void
160 etl::uninitialized_fill(begin(), end(), value);
163 constexpr auto deallocate() ->
void
169 etl::size_t _size{0};
170 etl::size_t _capacity{0};
Definition ranges_in_fun_result.hpp:12
Definition adjacent_find.hpp:9
Definition allocator_traits.hpp:88
constexpr auto begin() const -> T const *
Definition vector.hpp:95
constexpr auto capacity() -> etl::size_t
Definition vector.hpp:130
constexpr vector(etl::size_t n, T const &value, Allocator alloc=Allocator())
Definition vector.hpp:41
constexpr auto size() -> etl::size_t
Definition vector.hpp:120
constexpr auto end() -> T *
Definition vector.hpp:100
constexpr vector(vector const &o)=delete
constexpr vector()=default
constexpr auto size() const -> etl::size_t
Definition vector.hpp:125
constexpr auto empty() const -> bool
Definition vector.hpp:115
constexpr auto operator=(vector const &o) -> vector &=delete
constexpr auto clear() noexcept -> void
Definition vector.hpp:140
constexpr auto data() -> T *
Definition vector.hpp:80
constexpr vector(vector &&other) noexcept
Definition vector.hpp:55
constexpr auto data() const -> T const *
Definition vector.hpp:85
constexpr auto begin() -> T *
Definition vector.hpp:90
constexpr auto operator=(vector &&other) noexcept -> vector &
Definition vector.hpp:63
constexpr auto end() const -> T const *
Definition vector.hpp:105
constexpr auto empty() -> bool
Definition vector.hpp:110
constexpr vector(Allocator alloc)
Definition vector.hpp:36
constexpr ~vector() noexcept
Definition vector.hpp:72
constexpr vector(etl::size_t n, Allocator alloc=Allocator())
Definition vector.hpp:47
constexpr auto capacity() const -> etl::size_t
Definition vector.hpp:135
friend constexpr auto swap(vector &lhs, vector &rhs) -> void
Definition vector.hpp:146