tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
static_vector.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_VECTOR_STATIC_VECTOR_HPP
4#define TETL_VECTOR_STATIC_VECTOR_HPP
5
13#include <etl/_array/array.hpp>
22#include <etl/_iterator/end.hpp>
26#include <etl/_new/operator.hpp>
40
41namespace etl {
42namespace detail {
44template <typename T>
45struct static_vector_zero_storage {
46 using size_type = uint8_t;
47 using value_type = T;
48 using difference_type = ptrdiff_t;
49 using pointer = T*;
50 using const_pointer = T const*;
51
53 constexpr static_vector_zero_storage() = default;
54
56 constexpr static_vector_zero_storage(static_vector_zero_storage const&) = default;
57
59 constexpr auto operator=(static_vector_zero_storage const&) noexcept -> static_vector_zero_storage& = default;
60
62 constexpr static_vector_zero_storage(static_vector_zero_storage&&) noexcept = default;
63
65 constexpr auto operator=(static_vector_zero_storage&&) noexcept -> static_vector_zero_storage& = default;
66
68 ~static_vector_zero_storage() = default;
69
71 [[nodiscard]] static constexpr auto data() noexcept -> pointer { return nullptr; }
72
74 [[nodiscard]] static constexpr auto size() noexcept -> size_type { return 0; }
75
77 [[nodiscard]] static constexpr auto capacity() noexcept -> size_type { return 0; }
78
80 [[nodiscard]] static constexpr auto empty() noexcept -> bool { return true; }
81
83 [[nodiscard]] static constexpr auto full() noexcept -> bool { return true; }
84
88 template <typename... Args>
89 requires(is_constructible_v<T, Args...>)
90 static constexpr auto emplace_back(Args&&... /*unused*/) noexcept -> void
91 {
92 TETL_PRECONDITION(false);
93 }
94
97 static constexpr void pop_back() noexcept { TETL_PRECONDITION(false); }
98
99protected:
103 static constexpr void unsafe_set_size([[maybe_unused]] size_t newSize) noexcept { TETL_PRECONDITION(newSize == 0); }
104
108 template <typename InputIt>
109 static constexpr auto unsafe_destroy(InputIt /* begin */, InputIt /* end */) noexcept -> void
110 {
111 }
112
115 static constexpr void unsafe_destroy_all() noexcept { }
116};
117
119template <typename T, size_t Capacity>
120struct static_vector_trivial_storage {
121 static_assert(etl::is_trivial_v<T>);
122 static_assert(Capacity != size_t{0});
123
124 using size_type = etl::smallest_size_t<Capacity>;
125 using value_type = T;
126 using difference_type = ptrdiff_t;
127 using pointer = T*;
128 using const_pointer = T const*;
129
130 constexpr static_vector_trivial_storage() noexcept = default;
131
132 constexpr static_vector_trivial_storage(static_vector_trivial_storage const&) noexcept = default;
133 constexpr auto operator=(static_vector_trivial_storage const&) noexcept -> static_vector_trivial_storage& = default;
134
135 constexpr static_vector_trivial_storage(static_vector_trivial_storage&&) noexcept = default;
136 constexpr auto operator=(static_vector_trivial_storage&&) noexcept -> static_vector_trivial_storage& = default;
137
138 ~static_vector_trivial_storage() = default;
139
141 [[nodiscard]] constexpr auto data() const noexcept -> const_pointer { return _data.data(); }
142
144 [[nodiscard]] constexpr auto data() noexcept -> pointer { return _data.data(); }
145
147 [[nodiscard]] constexpr auto size() const noexcept -> size_type { return _size; }
148
151 [[nodiscard]] constexpr auto capacity() const noexcept -> size_type { return Capacity; }
152
154 [[nodiscard]] constexpr auto empty() const noexcept -> bool { return size() == size_type{0}; }
155
157 [[nodiscard]] constexpr auto full() const noexcept -> bool { return size() == Capacity; }
158
160 template <typename... Args>
162 constexpr auto emplace_back(Args&&... args) noexcept -> void
163 {
164 TETL_PRECONDITION(!full());
165 index(_data, size()) = T(etl::forward<Args>(args)...);
166 unsafe_set_size(static_cast<size_type>(size()) + 1U);
167 }
168
170 constexpr auto pop_back() noexcept -> void
171 {
172 TETL_PRECONDITION(!empty());
173 unsafe_set_size(static_cast<size_type>(size() - 1));
174 }
175
176protected:
180 constexpr auto unsafe_set_size(size_t newSize) noexcept -> void
181 {
182 TETL_PRECONDITION(newSize <= Capacity);
183 _size = size_type(newSize);
184 }
185
189 template <typename InputIt>
190 constexpr auto unsafe_destroy(InputIt /*unused*/, InputIt /*unused*/) noexcept -> void
191 {
192 }
193
197 constexpr auto unsafe_destroy_all() noexcept -> void { }
198
199private:
200 // If the value_type is const, make a const array of
201 // non-const elements:
203 alignas(alignof(T)) data_t _data{};
204
205 size_type _size = 0;
206};
207
209template <typename T, size_t Capacity>
210struct static_vector_non_trivial_storage {
211 static_assert(!is_trivial_v<T>);
212 static_assert(Capacity != size_t{0});
213
214 using size_type = etl::smallest_size_t<Capacity>;
215 using value_type = T;
216 using difference_type = ptrdiff_t;
217 using pointer = T*;
218 using const_pointer = T const*;
219
220 static_vector_non_trivial_storage() = default;
221
222 static_vector_non_trivial_storage(static_vector_non_trivial_storage const&) = default;
223 auto operator=(static_vector_non_trivial_storage const&) -> static_vector_non_trivial_storage& = default;
224
225 static_vector_non_trivial_storage(static_vector_non_trivial_storage&&) noexcept = default;
226 auto operator=(static_vector_non_trivial_storage&&) noexcept -> static_vector_non_trivial_storage& = default;
227
228 ~static_vector_non_trivial_storage() noexcept(is_nothrow_destructible_v<T>) { unsafe_destroy_all(); }
229
231 [[nodiscard]] auto data() const noexcept -> const_pointer { return reinterpret_cast<const_pointer>(_data); }
232
234 [[nodiscard]] auto data() noexcept -> pointer { return reinterpret_cast<pointer>(_data); }
235
237 [[nodiscard]] auto end() const noexcept -> const_pointer { return data() + size(); }
238
240 [[nodiscard]] auto end() noexcept -> pointer { return data() + size(); }
241
243 [[nodiscard]] auto size() const noexcept -> size_type { return _size; }
244
247 [[nodiscard]] auto capacity() const noexcept -> size_type { return Capacity; }
248
250 [[nodiscard]] auto empty() const noexcept -> bool { return size() == size_type{0}; }
251
253 [[nodiscard]] auto full() const noexcept -> bool { return size() == Capacity; }
254
257 template <typename... Args>
258 auto emplace_back(Args&&... args) noexcept(noexcept(new(end()) T(etl::forward<Args>(args)...))) -> void
259 {
260 TETL_PRECONDITION(!full());
261 new (end()) T(etl::forward<Args>(args)...);
262 unsafe_set_size(static_cast<size_type>(size() + 1));
263 }
264
266 auto pop_back() noexcept(is_nothrow_destructible_v<T>) -> void
267 {
268 TETL_PRECONDITION(!empty());
269 auto* ptr = end() - 1;
270 ptr->~T();
271 unsafe_set_size(static_cast<size_type>(size() - 1));
272 }
273
274protected:
278 auto unsafe_set_size(size_t newSize) noexcept -> void
279 {
280 TETL_PRECONDITION(newSize <= Capacity);
281 _size = size_type(newSize);
282 }
283
287 template <typename InputIt>
288 auto unsafe_destroy(InputIt first, InputIt last) noexcept(is_nothrow_destructible_v<T>) -> void
289 {
290 TETL_PRECONDITION(first >= data() and first <= end());
291 TETL_PRECONDITION(last >= data() and last <= end());
292 for (; first != last; ++first) {
293 first->~T();
294 }
295 }
296
300 auto unsafe_destroy_all() noexcept(is_nothrow_destructible_v<T>) -> void { unsafe_destroy(data(), end()); }
301
302private:
303 using raw_type = remove_const_t<T>;
304 using aligned = aligned_storage_t<sizeof(raw_type), alignof(raw_type)>;
305 using storage_type = conditional_t<!is_const_v<T>, aligned, aligned const>;
306
307 alignas(alignof(T)) storage_type _data[Capacity];
308 size_type _size = 0;
309};
310
312template <typename T, size_t Capacity>
313using static_vector_storage_type = conditional_t<
314 Capacity == 0,
315 static_vector_zero_storage<T>,
318 static_vector_trivial_storage<T, Capacity>,
319 static_vector_non_trivial_storage<T, Capacity>>>;
320
321} // namespace detail
322
328template <typename T, size_t Capacity>
329struct static_vector : detail::static_vector_storage_type<T, Capacity> {
330private:
331 static_assert(is_nothrow_destructible_v<T>);
332 using base_type = detail::static_vector_storage_type<T, Capacity>;
333 using self = static_vector<T, Capacity>;
334
335 using base_type::unsafe_destroy;
336 using base_type::unsafe_destroy_all;
337 using base_type::unsafe_set_size;
338
339public:
341 using value_type = typename base_type::value_type;
349 using pointer = typename base_type::pointer;
351 using const_pointer = typename base_type::const_pointer;
353 using iterator = typename base_type::pointer;
355 using const_iterator = typename base_type::const_pointer;
362
363private:
364 constexpr auto emplace_n(size_type n) noexcept(
367 ) -> void
368 {
370 while (n != size()) {
371 emplace_back(T{});
372 }
373 }
374
375public:
376 [[nodiscard]] constexpr auto begin() noexcept -> iterator { return data(); }
377
378 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator { return data(); }
379
380 [[nodiscard]] constexpr auto end() noexcept -> iterator { return data() + size(); }
381
382 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator { return data() + size(); }
383
384 [[nodiscard]] constexpr auto rbegin() noexcept -> reverse_iterator { return reverse_iterator(end()); }
385
386 [[nodiscard]] constexpr auto rbegin() const noexcept -> const_reverse_iterator
387 {
388 return const_reverse_iterator(end());
389 }
390
391 [[nodiscard]] constexpr auto rend() noexcept -> reverse_iterator { return reverse_iterator(begin()); }
392
393 [[nodiscard]] constexpr auto rend() const noexcept -> const_reverse_iterator
394 {
396 }
397
398 [[nodiscard]] constexpr auto cbegin() noexcept -> const_iterator { return begin(); }
399
400 [[nodiscard]] constexpr auto cbegin() const noexcept -> const_iterator { return begin(); }
401
402 [[nodiscard]] constexpr auto cend() noexcept -> const_iterator { return end(); }
403
404 [[nodiscard]] constexpr auto cend() const noexcept -> const_iterator { return end(); }
405
406 [[nodiscard]] constexpr auto crbegin() const noexcept -> const_reverse_iterator
407 {
408 return const_reverse_iterator(end());
409 }
410
411 [[nodiscard]] constexpr auto crend() const noexcept -> const_reverse_iterator
412 {
414 }
415
416 using base_type::emplace_back;
417
418 using base_type::pop_back;
419
421 template <typename U>
423 constexpr auto push_back(U&& value) noexcept(noexcept(emplace_back(etl::forward<U>(value)))) -> void
424 {
426 emplace_back(etl::forward<U>(value));
427 }
428
429 template <typename InIt>
430 requires(detail::InputIterator<InIt>)
431 constexpr auto move_insert(const_iterator position, InIt first, InIt last)
432 noexcept(noexcept(emplace_back(etl::move(*first)))) -> iterator
433 {
434 assert_iterator_in_range(position);
435 assert_valid_iterator_pair(first, last);
436 if constexpr (detail::RandomAccessIterator<InIt>) {
437 TETL_PRECONDITION(size() + static_cast<size_type>(last - first) <= capacity());
438 }
439 iterator b = end();
440
441 // we insert at the end and then just rotate:
442 for (; first != last; ++first) {
443 emplace_back(etl::move(*first));
444 }
445 auto* writablePosition = begin() + (position - begin());
446 rotate<iterator>(writablePosition, b, end());
447 return writablePosition;
448 }
449
450 template <typename... Args>
451 requires(is_constructible_v<T, Args...>)
452 constexpr auto emplace(const_iterator position, Args&&... args)
453 noexcept(noexcept(move_insert(position, declval<value_type*>(), declval<value_type*>()))) -> iterator
454 {
456 assert_iterator_in_range(position);
457 value_type a(etl::forward<Args>(args)...);
458 return move_insert(position, &a, &a + 1);
459 }
460
462 using base_type::data;
463
464 constexpr auto insert(const_iterator position, value_type&& x) noexcept(noexcept(move_insert(position, &x, &x + 1)))
465 -> iterator
467 {
469 assert_iterator_in_range(position);
470 return move_insert(position, &x, &x + 1);
471 }
472
473 constexpr auto insert(const_iterator position, size_type n, T const& x) noexcept(noexcept(push_back(x))) -> iterator
475 {
476 assert_iterator_in_range(position);
477 TETL_PRECONDITION(size() + n <= capacity());
478 auto* b = end();
479 while (n != 0) {
480 push_back(x);
481 --n;
482 }
483
484 auto* writablePosition = begin() + (position - begin());
485 rotate(writablePosition, b, end());
486 return writablePosition;
487 }
488
489 constexpr auto insert(const_iterator position, const_reference x)
490 noexcept(noexcept(insert(position, size_type(1), x))) -> iterator
492 {
494 assert_iterator_in_range(position);
495 return insert(position, size_type(1), x);
496 }
497
498 template <typename InputIt>
499 constexpr auto insert(const_iterator position, InputIt first, InputIt last) noexcept(noexcept(emplace_back(*first)))
500 -> iterator
501 requires(detail::InputIterator<InputIt> && is_constructible_v<value_type, detail::iterator_reference_t<InputIt>>)
502 {
503 assert_iterator_in_range(position);
504 assert_valid_iterator_pair(first, last);
505 if constexpr (detail::RandomAccessIterator<InputIt>) {
506 TETL_PRECONDITION(size() + static_cast<size_type>(last - first) <= capacity());
507 }
508 auto* b = end();
509
510 // insert at the end and then just rotate:
511 for (; first != last; ++first) {
512 emplace_back(*first);
513 }
514
515 auto* writablePosition = begin() + (position - begin());
516 rotate(writablePosition, b, end());
517 return writablePosition;
518 }
519
521 constexpr void clear() noexcept
522 {
523 unsafe_destroy_all();
524 unsafe_set_size(0);
525 }
526
527 constexpr static_vector() = default;
528
529 template <etl::same_as<empty_c_array> Source = empty_c_array>
530 constexpr static_vector(Source /*unused*/) noexcept
531 {
532 }
533
534 template <etl::size_t Size>
535 requires(Size <= Capacity)
536 constexpr static_vector(c_array<T, Size>&& source)
537 {
538 move_insert(begin(), etl::begin(source), etl::end(source));
539 }
540
542 constexpr static_vector(static_vector const& other) noexcept(noexcept(insert(begin(), other.begin(), other.end())))
543 {
544 // Nothing to assert: size of other cannot exceed capacity because both
545 // vectors have the same type
546 insert(begin(), other.begin(), other.end());
547 }
548
550 constexpr static_vector(static_vector&& other) noexcept(noexcept(move_insert(begin(), other.begin(), other.end())))
551 {
552 // Nothing to assert: size of other cannot exceed capacity because both
553 // vectors have the same type
554 move_insert(begin(), other.begin(), other.end());
555 }
556
558 constexpr auto operator=(static_vector const& other)
559 noexcept(noexcept(clear()) && noexcept(insert(begin(), other.begin(), other.end())))
561 // Nothing to assert: size of other cannot exceed capacity because both
562 // vectors have the same type
563 clear();
564 insert(begin(), other.begin(), other.end());
565 return *this;
566 }
567
569 constexpr auto operator=(static_vector&& other)
570 noexcept(noexcept(clear()) and noexcept(move_insert(begin(), other.begin(), other.end())))
572 // Nothing to assert: size of other cannot exceed capacity because both
573 // vectors have the same type
574 clear();
575 move_insert(begin(), other.begin(), other.end());
576 return *this;
577 }
578
580 explicit constexpr static_vector(size_type n) noexcept(noexcept(emplace_n(n)))
582 {
584 emplace_n(n);
585 }
586
588 constexpr static_vector(size_type n, T const& value) noexcept(noexcept(insert(begin(), n, value)))
590 {
592 insert(begin(), n, value);
593 }
594
596 template <typename InputIter>
597 requires(detail::InputIterator<InputIter>)
598 constexpr static_vector(InputIter first, InputIter last)
599 {
600 if constexpr (detail::RandomAccessIterator<InputIter>) {
601 TETL_PRECONDITION(last - first >= 0);
602 TETL_PRECONDITION(static_cast<size_type>(last - first) <= capacity());
603 }
604 insert(begin(), first, last);
605 }
606
608 using base_type::empty;
609
610 using base_type::full;
611
613 [[nodiscard]] constexpr auto size() const noexcept -> size_type { return base_type::size(); }
614
616 [[nodiscard]] constexpr auto capacity() const noexcept -> size_type { return base_type::capacity(); }
617
618 [[nodiscard]] constexpr auto max_size() const noexcept -> size_type { return capacity(); }
619
621 template <typename InputIter>
622 requires(detail::InputIterator<InputIter>)
623 constexpr auto assign(InputIter first, InputIter last)
624 noexcept(noexcept(clear()) and noexcept(insert(begin(), first, last))) -> void
625 {
626 if constexpr (detail::RandomAccessIterator<InputIter>) {
627 TETL_PRECONDITION(last - first >= 0);
628 TETL_PRECONDITION(static_cast<size_type>(last - first) <= capacity());
629 }
630 clear();
631 insert(begin(), first, last);
632 }
633
634 constexpr auto assign(size_type n, T const& u) -> void
636 {
638 clear();
639 insert(begin(), n, u);
640 }
641
643 [[nodiscard]] constexpr auto operator[](size_type pos) noexcept -> reference { return detail::index(*this, pos); }
644
646 [[nodiscard]] constexpr auto operator[](size_type pos) const noexcept -> const_reference
647 {
648 return detail::index(*this, pos);
649 }
650
652 [[nodiscard]] constexpr auto front() noexcept -> reference { return detail::index(*this, 0); }
653
654 [[nodiscard]] constexpr auto front() const noexcept -> const_reference { return detail::index(*this, 0); }
655
657 [[nodiscard]] constexpr auto back() noexcept -> reference
658 {
660 return detail::index(*this, static_cast<size_type>(size() - 1));
661 }
662
663 [[nodiscard]] constexpr auto back() const noexcept -> const_reference
664 {
666 return detail::index(*this, static_cast<size_type>(size() - 1));
667 }
668
670 constexpr auto erase(const_iterator position) noexcept -> iterator
671 requires(detail::is_movable_v<value_type>)
672 {
673 assert_iterator_in_range(position);
674 return erase(position, position + 1);
675 }
676
677 constexpr auto erase(const_iterator first, const_iterator last) noexcept -> iterator
678 requires(detail::is_movable_v<value_type>)
679 {
680 assert_iterator_pair_in_range(first, last);
681 iterator p = begin() + (first - begin());
682 if (first != last) {
683 unsafe_destroy(etl::move(p + (last - first), end(), p), end());
684 unsafe_set_size(size() - static_cast<size_type>(last - first));
685 }
686
687 return p;
688 }
689
691 constexpr auto swap(static_vector& other) noexcept(is_nothrow_swappable_v<T>) -> void
693 {
694 static_vector tmp = etl::move(other);
695 other = etl::move(*this);
696 (*this) = etl::move(tmp);
697 }
698
701 constexpr auto resize(size_type sz) noexcept(
704 ) -> void
705 requires(detail::is_movable_v<value_type>)
706 {
707 if (sz == size()) {
708 return;
709 }
710
711 if (sz > size()) {
712 emplace_n(sz);
713 return;
714 }
715
716 erase(end() - (size() - sz), end());
717 }
718
719 constexpr auto resize(size_type sz, T const& value) noexcept(is_nothrow_copy_constructible_v<T>) -> void
721 {
722 if (sz == size()) {
723 return;
724 }
725 if (sz > size()) {
727 insert(end(), sz - size(), value);
728 } else {
729 erase(end() - (size() - sz), end());
730 }
731 }
732
733private:
734 template <typename It>
735 constexpr void assert_iterator_in_range([[maybe_unused]] It it) noexcept
736 {
737 static_assert(is_pointer_v<It>);
738 TETL_PRECONDITION(begin() <= it);
739 TETL_PRECONDITION(it <= end());
740 }
741
742 template <typename It0, typename It1>
743 constexpr void assert_valid_iterator_pair([[maybe_unused]] It0 first, [[maybe_unused]] It1 last) noexcept
744 {
745 static_assert(is_pointer_v<It0>);
746 static_assert(is_pointer_v<It1>);
747 TETL_PRECONDITION(first <= last);
748 }
749
750 template <typename It0, typename It1>
751 constexpr void assert_iterator_pair_in_range([[maybe_unused]] It0 first, [[maybe_unused]] It1 last) noexcept
752 {
753 assert_iterator_in_range(first);
754 assert_iterator_in_range(last);
755 assert_valid_iterator_pair(first, last);
756 }
757};
758
761template <typename T, size_t Capacity>
762constexpr auto swap(static_vector<T, Capacity>& lhs, static_vector<T, Capacity>& rhs) noexcept -> void
763{
764 lhs.swap(rhs);
765}
766
772template <typename T, size_t Capacity>
773constexpr auto operator==(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
774{
775 if (size(lhs) == size(rhs)) {
776 return equal(begin(lhs), end(lhs), begin(rhs), end(rhs), equal_to{});
777 }
778
779 return false;
780}
781
782template <typename T, size_t Capacity>
783constexpr auto operator!=(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
784{
785 return !(lhs == rhs);
786}
787
793template <typename T, size_t Capacity>
794constexpr auto operator<(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
795{
796 return lexicographical_compare(begin(lhs), end(lhs), begin(rhs), end(rhs));
797}
798
799template <typename T, size_t Capacity>
800constexpr auto operator<=(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
801{
802 return !(rhs < lhs);
803}
804
805template <typename T, size_t Capacity>
806constexpr auto operator>(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
807{
808 return rhs < lhs;
809}
810
811template <typename T, size_t Capacity>
812constexpr auto operator>=(static_vector<T, Capacity> const& lhs, static_vector<T, Capacity> const& rhs) noexcept -> bool
813{
814 return !(lhs < rhs);
815}
816
822template <typename T, size_t Capacity, typename Predicate>
824{
825 auto* it = remove_if(c.begin(), c.end(), pred);
826 auto r = distance(it, c.end());
827 c.erase(it, c.end());
828 return static_cast<typename static_vector<T, Capacity>::size_type>(r);
829}
830
831template <typename T, size_t Capacity, typename U>
832constexpr auto erase(static_vector<T, Capacity>& c, U const& value) -> typename static_vector<T, Capacity>::size_type
833{
834 return erase_if(c, [&value](auto const& item) { return item == value; });
835}
836
837} // namespace etl
838
839#endif // TETL_VECTOR_STATIC_VECTOR_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto remove_if(ForwardIt first, ForwardIt last, Predicate pred) -> ForwardIt
Removes all elements satisfying specific criteria from the range [first, last) and returns a past-the...
Definition remove_if.hpp:16
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto rotate(ForwardIt first, ForwardIt nFirst, ForwardIt last) -> ForwardIt
Performs a left rotation on a range of elements.
Definition rotate.hpp:17
constexpr auto lexicographical_compare(InputIt1 f1, InputIt1 l1, InputIt2 f2, InputIt2 l2, Compare comp) -> bool
Checks if the first range [f1, l1) is lexicographically less than the second range [f2,...
Definition lexicographical_compare.hpp:17
constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, Predicate p) -> bool
Returns true if the range [first1, last1) is equal to the range [first2, first2 + (last1 - first1)),...
Definition equal.hpp:18
ValueType[Size] c_array
Definition c_array.hpp:12
constexpr auto empty(C const &c) noexcept(noexcept(c.empty())) -> decltype(c.empty())
Returns whether the given container is empty.
Definition empty.hpp:15
constexpr auto end(C &c) -> decltype(c.end())
Returns an iterator to the end (i.e. the element after the last element) of the given container c or ...
Definition end.hpp:14
constexpr auto full(C const &c) noexcept(noexcept(c.full())) -> decltype(c.full())
Returns whether the given container is full.
Definition full.hpp:14
constexpr auto distance(It first, It last) -> typename iterator_traits< It >::difference_type
Returns the number of hops from first to last.
Definition distance.hpp:16
constexpr auto data(C &c) noexcept(noexcept(c.data())) -> decltype(c.data())
Returns a pointer to the block of memory containing the elements of the container.
Definition data.hpp:11
constexpr auto size(C const &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Returns the size of the given container c or array array. Returns c.size(), converted to the return t...
Definition size.hpp:18
constexpr auto begin(C &c) -> decltype(c.begin())
Returns an iterator to the beginning of the given container c or array array. These templates rely on...
Definition begin.hpp:20
conditional_t<(N< static_cast< unsigned char >(-1)), unsigned char, conditional_t<(N< static_cast< unsigned short >(-1)), unsigned short, conditional_t<(N< static_cast< unsigned int >(-1)), unsigned int, conditional_t<(N< static_cast< unsigned long >(-1)), unsigned long, unsigned long long > > > > smallest_size_t
Smallest unsigned integer type that can represent values in the range [0, N].
Definition smallest_size_t.hpp:13
Definition adjacent_find.hpp:8
constexpr bool is_copy_constructible_v
Definition is_copy_constructible.hpp:30
constexpr auto operator==(inplace_function< R(Args...), Capacity, Alignment > const &f, nullptr_t) noexcept -> bool
Compares a etl::inplace_function with a null pointer. Empty functions (that is, functions without a c...
Definition inplace_function.hpp:262
typename conditional< B, T, F >::type conditional_t
Definition conditional.hpp:21
constexpr bool is_constructible_v
Definition is_constructible.hpp:24
constexpr bool is_nothrow_copy_constructible_v
Definition is_nothrow_copy_constructible.hpp:27
auto declval() noexcept -> add_rvalue_reference_t< T >
constexpr bool is_trivial_v
Definition is_trivial.hpp:22
constexpr bool is_nothrow_move_constructible_v
Definition is_nothrow_move_constructible.hpp:20
constexpr auto operator!=(inplace_function< R(Args...), Capacity, Alignment > const &f, nullptr_t) noexcept -> bool
Compares a etl::inplace_function with a null pointer. Empty functions (that is, functions without a c...
Definition inplace_function.hpp:272
constexpr bool is_move_constructible_v
Definition is_move_constructible.hpp:20
constexpr bool is_pointer_v
Definition is_pointer.hpp:30
TETL_BUILTIN_UINT8 uint8_t
Unsigned integer type with width of exactly 8 bits.
Definition uint_t.hpp:11
typename remove_const< T >::type remove_const_t
Definition remove_const.hpp:23
constexpr bool is_assignable_v
Definition is_assignable.hpp:20
constexpr auto operator<(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:167
constexpr auto erase(basic_inplace_string< Char, Capacity, Traits > &c, U const &value) noexcept -> typename basic_inplace_string< Char, Capacity, Traits >::size_type
Erases all elements that compare equal to value from the container.
Definition basic_inplace_string.hpp:1635
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
constexpr auto operator<=(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:177
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249
constexpr auto operator>(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:185
constexpr auto erase_if(etl::flat_set< Key, Container, Compare > &c, Pred pred) -> typename etl::flat_set< Key, Container, Compare >::size_type
Definition flat_set.hpp:385
constexpr auto operator>=(etl::reverse_iterator< Iter1 > const &lhs, etl::reverse_iterator< Iter2 > const &rhs) -> bool
Compares the underlying iterators. Inverse comparisons are applied in order to take into account that...
Definition reverse_iterator.hpp:195
constexpr bool is_nothrow_destructible_v
Definition is_nothrow_destructible.hpp:37
typename aligned_storage< Len, Align >::type aligned_storage_t
Definition aligned_storage.hpp:57
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
constexpr bool is_nothrow_swappable_v
Definition is_nothrow_swappable.hpp:19
array(T, U...) -> array< T, 1+sizeof...(U)>
One deduction guide is provided for array to provide an equivalent of experimental::make_array for co...
Function object for performing comparisons. Unless specialised, invokes operator== on type T....
Definition equal_to.hpp:14
reverse_iterator is an iterator adaptor that reverses the direction of a given iterator....
Definition reverse_iterator.hpp:22
Dynamically-resizable fixed-capacity vector.
Definition static_vector.hpp:329
typename base_type::pointer pointer
Definition static_vector.hpp:349
constexpr auto assign(InputIter first, InputIter last) noexcept(noexcept(clear()) and noexcept(insert(begin(), first, last))) -> void
assign
Definition static_vector.hpp:623
constexpr auto insert(const_iterator position, const_reference x) noexcept(noexcept(insert(position, size_type(1), x))) -> iterator requires(is_copy_constructible_v< T >)
Definition static_vector.hpp:489
constexpr auto operator[](size_type pos) const noexcept -> const_reference
Unchecked access to element at index pos (UB if index not in.
Definition static_vector.hpp:646
constexpr static_vector(InputIter first, InputIter last)
Initialize vector from range [first, last).
Definition static_vector.hpp:598
constexpr auto emplace(const_iterator position, Args &&... args) noexcept(noexcept(move_insert(position, declval< value_type * >(), declval< value_type * >()))) -> iterator
Definition static_vector.hpp:452
constexpr auto front() const noexcept -> const_reference
Definition static_vector.hpp:654
constexpr auto operator=(static_vector const &other) noexcept(noexcept(clear()) &&noexcept(insert(begin(), other.begin(), other.end()))) -> static_vector &requires(is_assignable_v< reference, const_reference >)
Copy assignment.
Definition static_vector.hpp:558
constexpr static_vector()=default
constexpr auto operator=(static_vector &&other) noexcept(noexcept(clear()) and noexcept(move_insert(begin(), other.begin(), other.end()))) -> static_vector &requires(is_assignable_v< reference, reference >)
Move assignment.
Definition static_vector.hpp:569
constexpr static_vector(static_vector &&other) noexcept(noexcept(move_insert(begin(), other.begin(), other.end())))
Move constructor.
Definition static_vector.hpp:550
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Definition static_vector.hpp:406
constexpr auto move_insert(const_iterator position, InIt first, InIt last) noexcept(noexcept(emplace_back(etl::move(*first)))) -> iterator
Definition static_vector.hpp:431
etl::reverse_iterator< const_iterator > const_reverse_iterator
Definition static_vector.hpp:361
constexpr auto insert(const_iterator position, size_type n, T const &x) noexcept(noexcept(push_back(x))) -> iterator requires(is_copy_constructible_v< T >)
Definition static_vector.hpp:473
value_type const & const_reference
Definition static_vector.hpp:347
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Definition static_vector.hpp:386
constexpr auto swap(static_vector &other) noexcept(is_nothrow_swappable_v< T >) -> void requires(is_assignable_v< T &, T && >)
Exchanges the contents of the container with those of other.
Definition static_vector.hpp:691
constexpr auto cend() noexcept -> const_iterator
Definition static_vector.hpp:402
constexpr auto back() noexcept -> reference
back
Definition static_vector.hpp:657
constexpr auto insert(const_iterator position, InputIt first, InputIt last) noexcept(noexcept(emplace_back(*first))) -> iterator requires(detail::InputIterator< InputIt > &&is_constructible_v< value_type, detail::iterator_reference_t< InputIt > >)
Definition static_vector.hpp:499
constexpr auto push_back(U &&value) noexcept(noexcept(emplace_back(etl::forward< U >(value)))) -> void
Appends value at the end of the vector.
Definition static_vector.hpp:423
constexpr auto rend() noexcept -> reverse_iterator
Definition static_vector.hpp:391
value_type & reference
Definition static_vector.hpp:345
constexpr auto begin() noexcept -> iterator
Definition static_vector.hpp:376
constexpr static_vector(Source) noexcept
Definition static_vector.hpp:530
constexpr auto end() noexcept -> iterator
Definition static_vector.hpp:380
constexpr auto begin() const noexcept -> const_iterator
Definition static_vector.hpp:378
constexpr auto cbegin() const noexcept -> const_iterator
Definition static_vector.hpp:400
constexpr auto resize(size_type sz, T const &value) noexcept(is_nothrow_copy_constructible_v< T >) -> void requires(is_copy_constructible_v< T >)
Definition static_vector.hpp:719
constexpr auto assign(size_type n, T const &u) -> void requires(is_copy_constructible_v< T >)
Definition static_vector.hpp:634
size_t size_type
Definition static_vector.hpp:357
typename base_type::pointer iterator
Definition static_vector.hpp:353
constexpr auto erase(const_iterator first, const_iterator last) noexcept -> iterator requires(detail::is_movable_v< value_type >)
Definition static_vector.hpp:677
constexpr auto operator[](size_type pos) noexcept -> reference
Unchecked access to element at index pos (UB if index not in.
Definition static_vector.hpp:643
constexpr void clear() noexcept
Clears the vector.
Definition static_vector.hpp:521
constexpr auto back() const noexcept -> const_reference
Definition static_vector.hpp:663
etl::reverse_iterator< iterator > reverse_iterator
Definition static_vector.hpp:359
constexpr auto front() noexcept -> reference
front
Definition static_vector.hpp:652
constexpr auto erase(const_iterator position) noexcept -> iterator requires(detail::is_movable_v< value_type >)
erase
Definition static_vector.hpp:670
constexpr auto max_size() const noexcept -> size_type
Definition static_vector.hpp:618
constexpr static_vector(size_type n, T const &value) noexcept(noexcept(insert(begin(), n, value)))
Initializes vector with n with value.
Definition static_vector.hpp:588
constexpr auto resize(size_type sz) noexcept((is_move_constructible_v< T > &&is_nothrow_move_constructible_v< T >)||(is_copy_constructible_v< T > &&is_nothrow_copy_constructible_v< T >)) -> void requires(detail::is_movable_v< value_type >)
Resizes the container to contain sz elements. If elements need to be appended, these are move-constru...
Definition static_vector.hpp:701
constexpr auto end() const noexcept -> const_iterator
Definition static_vector.hpp:382
typename base_type::const_pointer const_iterator
Definition static_vector.hpp:355
constexpr auto crend() const noexcept -> const_reverse_iterator
Definition static_vector.hpp:411
constexpr auto insert(const_iterator position, value_type &&x) noexcept(noexcept(move_insert(position, &x, &x+1))) -> iterator requires(is_move_constructible_v< T >)
Definition static_vector.hpp:464
constexpr static_vector(c_array< T, Size > &&source)
Definition static_vector.hpp:536
constexpr static_vector(static_vector const &other) noexcept(noexcept(insert(begin(), other.begin(), other.end())))
Copy constructor.
Definition static_vector.hpp:542
constexpr auto rend() const noexcept -> const_reverse_iterator
Definition static_vector.hpp:393
ptrdiff_t difference_type
Definition static_vector.hpp:343
constexpr auto size() const noexcept -> size_type
Number of elements in the vector.
Definition static_vector.hpp:613
constexpr auto cend() const noexcept -> const_iterator
Definition static_vector.hpp:404
constexpr auto capacity() const noexcept -> size_type
Maximum number of elements that can be allocated in the vector.
Definition static_vector.hpp:616
typename base_type::const_pointer const_pointer
Definition static_vector.hpp:351
constexpr static_vector(size_type n) noexcept(noexcept(emplace_n(n)))
Initializes vector with n default-constructed elements.
Definition static_vector.hpp:580
constexpr auto rbegin() noexcept -> reverse_iterator
Definition static_vector.hpp:384
typename base_type::value_type value_type
Definition static_vector.hpp:341
constexpr auto cbegin() noexcept -> const_iterator
Definition static_vector.hpp:398