Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix address_of for overloaded operator& #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Should not remove reference
  • Loading branch information
frederick-vs-ja authored Mar 14, 2024
commit 962250ec6bbc1e82bdc68c3cd61b116dda03f155
6 changes: 2 additions & 4 deletions MyTinySTL/memory.h
Original file line number Diff line number Diff line change
@@ -36,16 +36,14 @@ constexpr Tp* address_of(Tp& value) noexcept
}
#else
// 对于对象类型和函数类型分别使用不同的策略
template <class Tp, typename std::enable_if<std::is_object<
typename std::remove_reference<Tp>::type>::value, int>::type = 0>
template <class Tp, typename std::enable_if<std::is_object<Tp>::value, int>::type = 0>
Tp* address_of(Tp& value) noexcept
{
return const_cast<Tp*>(reinterpret_cast<const volatile Tp*>(
&reinterpret_cast<const volatile unsigned char&>(value)));
}

template <class Tp, typename std::enable_if<!std::is_object<
typename std::remove_reference<Tp>::type>::value, int>::type = 0>
template <class Tp, typename std::enable_if<!std::is_object<Tp>::value, int>::type = 0>
constexpr Tp* address_of(Tp& value) noexcept
{
return &value;