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
3#ifndef TETL_MEMORY_DESTROY_AT_HPP
4#define TETL_MEMORY_DESTROY_AT_HPP
5
8
9namespace etl {
10
15template <typename T>
16constexpr auto destroy_at(T* p) -> void
17{
18 if constexpr (is_array_v<T>) {
19 for (auto& elem : *p) {
20 destroy_at(addressof(elem));
21 }
22 } else {
23 p->~T();
24 }
25}
26
27} // namespace etl
28
29#endif // TETL_MEMORY_DESTROY_AT_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 bool is_array_v
Definition is_array.hpp:26
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:16