blob: b6fd3f28da5f6d1a61b1e4905aebbc82124dbafa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
#ifndef MPT_BASE_POINTER_HPP
#define MPT_BASE_POINTER_HPP
#include "mpt/base/namespace.hpp"
#include <cstddef>
namespace mpt {
inline namespace MPT_INLINE_NS {
inline constexpr int arch_bits = sizeof(void *) * 8;
inline constexpr std::size_t pointer_size = sizeof(void *);
template <typename Tdst, typename Tsrc>
struct pointer_cast_helper {
static constexpr Tdst cast(const Tsrc & src) noexcept {
return src;
}
};
template <typename Tdst, typename Tptr>
struct pointer_cast_helper<Tdst, const Tptr *> {
static constexpr Tdst cast(const Tptr * const & src) noexcept {
return reinterpret_cast<const Tdst>(src);
}
};
template <typename Tdst, typename Tptr>
struct pointer_cast_helper<Tdst, Tptr *> {
static constexpr Tdst cast(const Tptr * const & src) noexcept {
return reinterpret_cast<const Tdst>(src);
}
};
template <typename Tdst, typename Tsrc>
constexpr Tdst pointer_cast(const Tsrc & src) noexcept {
return pointer_cast_helper<Tdst, Tsrc>::cast(src);
}
} // namespace MPT_INLINE_NS
} // namespace mpt
#endif // MPT_BASE_POINTER_HPP
|