tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
set.cpp
// SPDX-License-Identifier: BSL-1.0
#undef NDEBUG
#include <etl/array.hpp>
#include <etl/cassert.hpp>
#include <etl/iterator.hpp>
#include <etl/set.hpp>
#include <stdio.h>
auto main() -> int
{
// Basic usage
set1.insert(3); // 3
set1.insert(1); // 1, 3
set1.insert(2); // 1, 2, 3
set1.insert(4); // 1, 2, 3, 4
set1.insert(4); // 1, 2, 3, 4
etl::for_each(set1.begin(), set1.end(), [](auto key) { ::printf("%d\n", key); });
assert(set1.contains(2));
assert(not set1.contains(5));
// Construct from range
auto data = etl::array{1.0F, 2.0F, 3.0F};
auto set2 = etl::static_set<float, 3>{data.begin(), data.end()};
assert(set2.full());
assert(set2.size() == 3);
assert(set2.count(1.0F) == 1);
return 0;
}
#define assert(...)
Definition cassert.hpp:19
constexpr auto for_each(InputIt first, InputIt last, UnaryFunc f) noexcept -> UnaryFunc
Applies the given function object f to the result of dereferencing every iterator in the range [first...
Definition for_each.hpp:20
A container that encapsulates fixed size arrays.
Definition array.hpp:48
static_set is an associative container that contains a sorted set of unique objects of type Key....
Definition static_set.hpp:29
constexpr auto contains(key_type const &key) const noexcept -> bool
Checks if there is an element with key equivalent to key in the container.
Definition static_set.hpp:317
constexpr auto begin() noexcept -> iterator
Returns an iterator to the first element of the set.
Definition static_set.hpp:90
constexpr auto end() noexcept -> iterator
Returns an iterator to the element following the last element of the set.
Definition static_set.hpp:100
constexpr auto insert(value_type &&value) -> pair< iterator, bool > requires(is_move_constructible_v< value_type >)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition static_set.hpp:164