tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
uninitialized_copy.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MEMORY_UNINITIALIZED_COPY_HPP
4#define TETL_MEMORY_UNINITIALIZED_COPY_HPP
5
9
10namespace etl {
11
12template <typename InputIt, typename NoThrowForwardIt>
13constexpr auto uninitialized_copy(InputIt first, InputIt last, NoThrowForwardIt dest) -> NoThrowForwardIt
14{
15#if defined(__cpp_exceptions)
16 auto current = dest;
17 try {
18 for (; first != last; ++first, (void)++current) {
19 etl::construct_at(etl::addressof(*current), *first);
20 }
21 return current;
22 } catch (...) {
23 etl::destroy(dest, current);
24 throw;
25 }
26#else
27 auto current = dest;
28 for (; first != last; ++first, (void)++current) {
29 etl::construct_at(etl::addressof(*current), *first);
30 }
31 return current;
32#endif
33}
34
35} // namespace etl
36
37#endif // TETL_MEMORY_UNINITIALIZED_COPY_HPP
Definition adjacent_find.hpp:8
constexpr auto addressof(T &arg) noexcept -> T *
Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
Definition addressof.hpp:15
constexpr auto uninitialized_copy(InputIt first, InputIt last, NoThrowForwardIt dest) -> NoThrowForwardIt
Definition uninitialized_copy.hpp:13
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 destroy(ForwardIt first, ForwardIt last) -> void
Destroys the objects in the range [first, last).
Definition destroy.hpp:13