-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[libc++] Make forward_list constexpr as part of P3372R3 #129435
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
Changes from all commits
838c50f
3d213b1
b6fd6de
a5b63dd
7c90175
6b7800a
30daee8
1b3743e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,8 +245,8 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(_Tp* __p) noexcept { | |
} | ||
|
||
template <class _Pointer> | ||
inline _LIBCPP_HIDE_FROM_ABI constexpr auto | ||
to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) { | ||
inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(const _Pointer& __p) noexcept | ||
-> decltype(std::__to_address(__p)) { | ||
return std::__to_address(__p); | ||
} | ||
#endif | ||
|
@@ -302,6 +302,18 @@ concept __resettable_smart_pointer_with_args = requires(_Smart __s, _Pointer __p | |
|
||
#endif | ||
|
||
// This function ensures safe conversions between fancy pointers at compile-time, where we avoid casts from/to | ||
// `__void_pointer` by obtaining the underlying raw pointer from the fancy pointer using `std::to_address`, | ||
// then dereferencing it to retrieve the pointed-to object, and finally constructing the target fancy pointer | ||
// to that object using the `std::pointer_traits<>::pinter_to` function. | ||
template <class _PtrTo, class _PtrFrom> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _PtrTo __static_fancy_pointer_cast(const _PtrFrom& __p) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document what this function does with a short comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we can't replace the cases like we did in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to #130310 ? If so, that PR (which hasn't landed yet) removes many instances of these casts, but not all of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess so. I think my main question is whether this utility is still needed after that patch. If not, I think I'd like this patch to be rebased on the other instead of adding a utility we know for a fact is removed by a follow-up patch. That would simplify this patch, which I think is quite important. The "constexpr everything" patches are really difficult to go through due to all the changes (even though none of them are complicated), so every bit of simplification makes it significantly easier to look at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what #130310 really does is to inline the three cast functions That said, I’d like to land this patch first to guarantee that all fancy pointer-related casts function correctly. Once that’s done, #130310 can rebase and serve as a follow-up to inline the three cast functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using the full definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I intentionally changed that private constructor to public in my demo, in order to mimic the use of that private constructor in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw that. My point was that with the full definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe @winner245 's point is that if you have a Given this, I believe it is reasonable to unblock this patch landing and clean it up slightly after landing #130310 -- that's also the author's preference in terms of ease-of-rebasing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I didn't see that. OTOH that error is entirely unrelated to the error in the original link. Given the claim that #130310 doesn't remove the need for the helper I do think that that's worth blocking over though. This is something we should look into before introducing a questionable workaround. |
||
using __ptr_traits = pointer_traits<_PtrTo>; | ||
using __element_type = typename __ptr_traits::element_type; | ||
return __p ? __ptr_traits::pointer_to(*static_cast<__element_type*>(std::addressof(*__p))) | ||
: static_cast<_PtrTo>(nullptr); | ||
} | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
Uh oh!
There was an error while loading. Please reload this page.