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
3#ifndef TETL_MEMORY_UNINITIALIZED_FILL_HPP
4#define TETL_MEMORY_UNINITIALIZED_FILL_HPP
5
9
10namespace etl {
11
12template <typename ForwardIt, typename T>
13constexpr auto uninitialized_fill(ForwardIt first, ForwardIt last, T const& value) -> void
14{
15#if defined(__cpp_exceptions)
16 auto current = first;
17 try {
18 for (; current != last; ++current) {
19 etl::construct_at(current, value);
20 }
21 } catch (...) {
22 using ValueType = typename etl::iterator_traits<ForwardIt>::value_type;
23 for (; first != current; ++first) {
24 first->~ValueType();
25 }
26 throw;
27 }
28#else
29 for (auto current = first; current != last; ++current) {
30 etl::construct_at(current, value);
31 }
32#endif
33}
34
35} // namespace etl
36
37#endif // TETL_MEMORY_UNINITIALIZED_FILL_HPP
Definition adjacent_find.hpp:8
constexpr auto construct_at(T *p, Args &&... args) -> T *
Creates a T object initialized with arguments args... at given address p.
Definition construct_at.hpp:38
constexpr auto uninitialized_fill(ForwardIt first, ForwardIt last, T const &value) -> void
Definition uninitialized_fill.hpp:13
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:47