tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
flat_multiset.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_FLAT_SET_FLAT_MULTISET_HPP
5#define TETL_FLAT_SET_FLAT_MULTISET_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_algorithm/sort.hpp>
10#include <etl/_flat_set/sorted_equivalent.hpp>
11#include <etl/_functional/less.hpp>
12#include <etl/_iterator/reverse_iterator.hpp>
13#include <etl/_utility/move.hpp>
14
15namespace etl {
16
17template <typename Key, typename KeyContainer, typename Compare = less<Key>>
19 using key_type = Key;
20 using value_type = Key;
21 using key_compare = Compare;
22 using value_compare = Compare;
23 using reference = value_type&;
24 using const_reference = value_type const&;
25 using size_type = typename KeyContainer::size_type;
26 using difference_type = typename KeyContainer::difference_type;
27 using iterator = typename KeyContainer::iterator;
28 using const_iterator = typename KeyContainer::const_iterator;
29 using reverse_iterator = etl::reverse_iterator<iterator>;
30 using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
31 using container_type = KeyContainer;
32
33 constexpr flat_multiset()
34 : flat_multiset(Compare())
35 {
36 }
37
38 explicit constexpr flat_multiset(Compare const& comp)
39 : _container()
40 , _compare(comp)
41 {
42 }
43
44 explicit constexpr flat_multiset(KeyContainer cont)
45 : flat_multiset(sorted_equivalent, etl::move(cont))
46 {
47 etl::sort(begin(), end(), _compare);
48 }
49
50 constexpr flat_multiset(sorted_equivalent_t /*tag*/, KeyContainer cont)
51 : _container(etl::move(cont))
52 , _compare()
53 {
54 }
55
56 [[nodiscard]] constexpr auto begin() noexcept -> iterator
57 {
58 return _container.begin();
59 }
60 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator
61 {
62 return _container.begin();
63 }
64 [[nodiscard]] constexpr auto cbegin() const noexcept -> const_iterator
65 {
66 return _container.begin();
67 }
68
69 [[nodiscard]] constexpr auto end() noexcept -> iterator
70 {
71 return _container.end();
72 }
73 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator
74 {
75 return _container.end();
76 }
77 [[nodiscard]] constexpr auto cend() const noexcept -> const_iterator
78 {
79 return _container.end();
80 }
81
82 [[nodiscard]] constexpr auto rbegin() noexcept -> reverse_iterator
83 {
84 return _container.rbegin();
85 }
86 [[nodiscard]] constexpr auto rbegin() const noexcept -> const_reverse_iterator
87 {
88 return _container.rbegin();
89 }
90 [[nodiscard]] constexpr auto crbegin() const noexcept -> const_reverse_iterator
91 {
92 return _container.crbegin();
93 }
94
95 [[nodiscard]] constexpr auto rend() noexcept -> reverse_iterator
96 {
97 return _container.rend();
98 }
99 [[nodiscard]] constexpr auto rend() const noexcept -> const_reverse_iterator
100 {
101 return _container.rend();
102 }
103 [[nodiscard]] constexpr auto crend() const noexcept -> const_reverse_iterator
104 {
105 return _container.crend();
106 }
107
108 [[nodiscard]] constexpr auto empty() const noexcept -> bool
109 {
110 return _container.empty();
111 }
112 [[nodiscard]] constexpr auto size() const noexcept -> size_type
113 {
114 return _container.size();
115 }
116 [[nodiscard]] constexpr auto max_size() const noexcept -> size_type
117 {
118 return _container.max_size();
119 }
120
121private:
122 TETL_NO_UNIQUE_ADDRESS KeyContainer _container;
123 TETL_NO_UNIQUE_ADDRESS Compare _compare;
124};
125
126} // namespace etl
127
128#endif // TETL_FLAT_SET_FLAT_MULTISET_HPP
Definition adjacent_find.hpp:9
constexpr auto sorted_equivalent
Definition sorted_equivalent.hpp:13
Definition flat_multiset.hpp:18
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Definition flat_multiset.hpp:90
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Definition flat_multiset.hpp:86
constexpr flat_multiset(Compare const &comp)
Definition flat_multiset.hpp:38
constexpr auto rend() noexcept -> reverse_iterator
Definition flat_multiset.hpp:95
constexpr auto begin() noexcept -> iterator
Definition flat_multiset.hpp:56
constexpr auto end() noexcept -> iterator
Definition flat_multiset.hpp:69
constexpr auto begin() const noexcept -> const_iterator
Definition flat_multiset.hpp:60
constexpr auto cbegin() const noexcept -> const_iterator
Definition flat_multiset.hpp:64
constexpr flat_multiset()
Definition flat_multiset.hpp:33
constexpr auto empty() const noexcept -> bool
Definition flat_multiset.hpp:108
constexpr flat_multiset(sorted_equivalent_t, KeyContainer cont)
Definition flat_multiset.hpp:50
constexpr auto max_size() const noexcept -> size_type
Definition flat_multiset.hpp:116
constexpr auto end() const noexcept -> const_iterator
Definition flat_multiset.hpp:73
constexpr auto crend() const noexcept -> const_reverse_iterator
Definition flat_multiset.hpp:103
constexpr auto rend() const noexcept -> const_reverse_iterator
Definition flat_multiset.hpp:99
constexpr auto size() const noexcept -> size_type
Definition flat_multiset.hpp:112
constexpr auto cend() const noexcept -> const_iterator
Definition flat_multiset.hpp:77
constexpr flat_multiset(KeyContainer cont)
Definition flat_multiset.hpp:44
constexpr auto rbegin() noexcept -> reverse_iterator
Definition flat_multiset.hpp:82
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15
Definition sorted_equivalent.hpp:9