Skip to content

Commit e78b0c1

Browse files
committed
Make addressof constexpr by using the builtin
1 parent 1c1d278 commit e78b0c1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

mem/addressof.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ namespace sus::mem {
2020

2121
template <class T>
2222
requires(std::is_object_v<T>)
23-
T* addressof(T& arg) noexcept {
24-
return reinterpret_cast<T*>(
25-
&const_cast<char&>(reinterpret_cast<const volatile char&>(arg)));
23+
constexpr T* addressof(T& arg) noexcept {
24+
return __builtin_addressof(arg);
2625
}
2726

2827
template <class T>
2928
requires(!std::is_object_v<T>)
30-
T* addressof(T& arg) noexcept {
29+
constexpr T* addressof(T& arg) noexcept {
3130
return &arg;
3231
}
3332

0 commit comments

Comments
 (0)