tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
destroy_at.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_MEMORY_DESTROY_AT_HPP
5#define TETL_MEMORY_DESTROY_AT_HPP
6
7#include <etl/_memory/addressof.hpp>
8#include <etl/_type_traits/is_array.hpp>
9
10namespace etl {
11
12/// \brief If T is not an array type, calls the destructor of the object pointed
13/// to by p, as if by p->~T(). If T is an array type, recursively destroys
14/// elements of *p in order, as if by calling destroy(begin(*p),
15/// end(*p)).
16template <typename T>
17constexpr auto destroy_at(T* p) -> void
18{
19 if constexpr (is_array_v<T>) {
20 for (auto& elem : *p) {
21 destroy_at(addressof(elem));
22 }
23 } else {
24 p->~T();
25 }
26}
27
28} // namespace etl
29
30#endif // TETL_MEMORY_DESTROY_AT_HPP
Definition adjacent_find.hpp:9
constexpr auto destroy_at(T *p) -> void
If T is not an array type, calls the destructor of the object pointed to by p, as if by p->~T()....
Definition destroy_at.hpp:17