VCCC  2024.05
VisualCamp Common C++ library
addressof.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/28/24.
3 //
4 
5 #ifndef VCCC_MEMORY_ADDRESSOF_HPP_
6 #define VCCC_MEMORY_ADDRESSOF_HPP_
7 
8 #include <memory>
9 #include <type_traits>
10 
11 #include "vccc/__config.h"
12 
13 # if __cplusplus < 201703L && !VCCC_CONSTEXPR_BUILTIN_ADDRESSOF_CXX14
14 # define VCCC_ADDRESSOF_CONSTEXPR
15 # else
16 # define VCCC_ADDRESSOF_CONSTEXPR constexpr
17 # endif
18 
19 namespace vccc {
20 
23 
24 # if __cplusplus < 201703L
25 # if VCCC_CONSTEXPR_BUILTIN_ADDRESSOF_CXX14
26 template<typename T>
27 constexpr T* addressof(T& t) noexcept {
28  return __builtin_addressof(t);
29 }
30 # else
31 template<typename T>
33 addressof(T& t) noexcept {
34  return
35  reinterpret_cast<T*>(
36  &const_cast<char&>(
37  reinterpret_cast<const volatile char&>(t)
38  )
39  );
40 }
41 template<typename T>
42 constexpr std::enable_if_t<std::is_object<T>::value == false, T*>
43 addressof(T& t) noexcept {
44  return &t;
45 }
46 # endif
47 # else
48 template<typename T>
49 constexpr T* addressof(T& t) noexcept {
50  return std::addressof(t);
51 }
52 # endif
53 
54 template<typename T>
55 constexpr const T* addressof(T&&) = delete;
56 
58 
59 } // namespace vccc
60 
61 #endif // VCCC_MEMORY_ADDRESSOF_HPP_
constexpr const T * addressof(T &&)=delete
std::enable_if_t< std::is_object< T >::value, T * > addressof(T &t) noexcept
Definition: addressof.hpp:33
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35