tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
pointer_traits.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MEMORY_POINTER_TRAITS_HPP
4#define TETL_MEMORY_POINTER_TRAITS_HPP
5
9
10namespace etl {
11
16template <typename Ptr>
18 using pointer = Ptr;
19 using element_type = typename Ptr::element_type;
20 using difference_type = typename Ptr::difference_type;
21
30 [[nodiscard]] static auto pointer_to(element_type& r) -> pointer { return Ptr::pointer_to(r); }
31};
32
39template <typename T>
40struct pointer_traits<T*> {
41 using pointer = T*;
42 using element_type = T;
44 template <typename U>
45 using rebind = U*;
46
54 [[nodiscard]] static auto pointer_to(T& r) -> pointer
55 requires(not etl::is_void_v<T>)
56 {
57 return etl::addressof(r);
58 }
59};
60
61} // namespace etl
62
63#endif // TETL_MEMORY_POINTER_TRAITS_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_void_v
Definition is_void.hpp:16
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
etl::ptrdiff_t difference_type
Definition pointer_traits.hpp:43
static auto pointer_to(T &r) -> pointer requires(not etl::is_void_v< T >)
Constructs a dereferenceable pointer or pointer-like object ("fancy pointer") to its argument.
Definition pointer_traits.hpp:54
U * rebind
Definition pointer_traits.hpp:45
T * pointer
Definition pointer_traits.hpp:41
T element_type
Definition pointer_traits.hpp:42
The pointer_traits class template provides the standardized way to access certain properties of point...
Definition pointer_traits.hpp:17
typename Ptr::difference_type difference_type
Definition pointer_traits.hpp:20
typename Ptr::element_type element_type
Definition pointer_traits.hpp:19
static auto pointer_to(element_type &r) -> pointer
Constructs a dereferenceable pointer or pointer-like object ("fancy pointer") to its argument.
Definition pointer_traits.hpp:30
Ptr pointer
Definition pointer_traits.hpp:18