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// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_MEMORY_UNINITIALIZED_COPY_HPP
5#define TETL_MEMORY_UNINITIALIZED_COPY_HPP
6
7#include <etl/_memory/addressof.hpp>
8#include <etl/_memory/construct_at.hpp>
9#include <etl/_memory/destroy.hpp>
10
11namespace etl {
12
13template <typename InputIt, typename NoThrowForwardIt>
14constexpr auto uninitialized_copy(InputIt first, InputIt last, NoThrowForwardIt dest) -> NoThrowForwardIt
15{
16#if defined(__cpp_exceptions)
17 auto current = dest;
18 try {
19 for (; first != last; ++first, (void)++current) {
20 etl::construct_at(etl::addressof(*current), *first);
21 }
22 return current;
23 } catch (...) {
24 etl::destroy(dest, current);
25 throw;
26 }
27#else
28 auto current = dest;
29 for (; first != last; ++first, (void)++current) {
30 etl::construct_at(etl::addressof(*current), *first);
31 }
32 return current;
33#endif
34}
35
36} // namespace etl
37
38#endif // TETL_MEMORY_UNINITIALIZED_COPY_HPP
Definition adjacent_find.hpp:9
constexpr auto uninitialized_copy(InputIt first, InputIt last, NoThrowForwardIt dest) -> NoThrowForwardIt
Definition uninitialized_copy.hpp:14