tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
operator.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_NEW_OPERATOR_HPP
5#define TETL_NEW_OPERATOR_HPP
6
7#include <etl/_cstddef/size_t.hpp>
8#include <etl/_utility/ignore_unused.hpp>
9
10// Some parts of the new header are declared in the global namespace. To avoid
11// ODR violations, we include the header <new> if it is available.
12#if __has_include(<new>)
13 #include <new>
14#else
15
16/// \brief Called by the standard single-object placement new expression. The
17/// standard library implementation performs no action and returns ptr
18/// unmodified. The behavior is undefined if this function is called through a
19/// placement new expression and ptr is a null pointer.
20[[nodiscard]] inline auto operator new(etl::size_t count, void* ptr) noexcept -> void*
21{
22 etl::ignore_unused(count);
23 return ptr;
24}
25
26/// \brief Called by the standard array form placement new expression. The
27/// standard library implementation performs no action and returns ptr
28/// unmodified. The behavior is undefined if this function is called through a
29/// placement new expression and ptr is a null pointer.
30[[nodiscard]] inline auto operator new[](etl::size_t count, void* ptr) noexcept -> void*
31{
32 etl::ignore_unused(count);
33 return ptr;
34}
35
36inline auto operator delete(void* /*ignore*/, void* /*ignore*/) noexcept -> void { }
37inline auto operator delete[](void* /*ignore*/, void* /*ignore*/) noexcept -> void { }
38
39#endif
40
41#endif // TETL_NEW_OPERATOR_HPP