tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
set.cpp
// SPDX-License-Identifier: BSL-1.0
// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
#include <etl/cassert.hpp>
#if defined(TETL_ENABLE_CXX_MODULES)
import etl;
#else
#include <etl/algorithm.hpp>
#include <etl/array.hpp>
#include <etl/iterator.hpp>
#include <etl/set.hpp>
#endif
#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:20
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:21
A container that encapsulates fixed size arrays.
Definition array.hpp:49
The class template bitset represents a fixed-size sequence of Bits bits. Bitsets can be manipulated b...
Definition bitset.hpp:23