tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
addressof.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_ADDRESSOF_HPP
5#define TETL_MEMORY_ADDRESSOF_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_type_traits/is_object.hpp>
10
11namespace etl {
12
13/// Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
14template <typename T>
15 requires(is_object_v<T>)
16constexpr auto addressof(T& arg) noexcept -> T*
17{
18 return __builtin_addressof(arg);
19}
20
21/// Obtains the actual address of the object or function arg, even in presence of overloaded operator&.
22template <typename T>
23 requires(not is_object_v<T>)
24constexpr auto addressof(T& arg) noexcept -> T*
25{
26 return &arg;
27}
28
29template <typename T>
30auto addressof(T const&& /*ignore*/) = delete;
31
32} // namespace etl
33
34#endif // TETL_MEMORY_ADDRESSOF_HPP
Definition adjacent_find.hpp:9
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:16
auto addressof(T const &&)=delete