tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
uninitialized_fill.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_MEMORY_UNINITIALIZED_FILL_HPP
5#define TETL_MEMORY_UNINITIALIZED_FILL_HPP
6
7#include <etl/_iterator/iterator_traits.hpp>
8#include <etl/_memory/addressof.hpp>
9#include <etl/_memory/construct_at.hpp>
10
11namespace etl {
12
13template <typename ForwardIt, typename T>
14constexpr auto uninitialized_fill(ForwardIt first, ForwardIt last, T const& value) -> void
15{
16#if defined(__cpp_exceptions)
17 auto current = first;
18 try {
19 for (; current != last; ++current) {
20 etl::construct_at(current, value);
21 }
22 } catch (...) {
23 using ValueType = typename etl::iterator_traits<ForwardIt>::value_type;
24 for (; first != current; ++first) {
25 first->~ValueType();
26 }
27 throw;
28 }
29#else
30 for (auto current = first; current != last; ++current) {
31 etl::construct_at(current, value);
32 }
33#endif
34}
35
36} // namespace etl
37
38#endif // TETL_MEMORY_UNINITIALIZED_FILL_HPP
Definition adjacent_find.hpp:9
constexpr auto uninitialized_fill(ForwardIt first, ForwardIt last, T const &value) -> void
Definition uninitialized_fill.hpp:14
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:48