-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<memory> construct_at() #501
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
Conversation
|
I don't think there should be any conditional compilation for the constexpr new thing, since in that case the construct_at call itself is likely to be needed to be treated as special by compilers. |
So should I just make it |
|
I would not declare constexpr anything here. |
|
@AdamBucior Are you happy with my changes? |
|
Yes, thanks! |
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Outdated
Show resolved
Hide resolved
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Outdated
Show resolved
Hide resolved
|
|
|
||
| struct X {}; | ||
|
|
||
| template <class _Void, class Ty, class... Types> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Ugly.
| template <class _Void, class Ty, class... Types> | |
| template <class Void, class Ty, class... Types> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I'm here typing, do you think it would help readability to add this void in an intermediate layer and unclutter the call sites?
| static_assert(!can_construct_at<void, int, X>); | ||
| static_assert(!can_construct_at<void, X, int>); | ||
|
|
||
| static_assert(!can_construct_at<void, int&>); // note that references can be constructed by not new'd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"by" should be "but". I also find "new'd" an odd contraction. Maybe "note that new only works with object types"?
Actually, it seems a bit silly to test reference types here given that the function deduces the type from a pointer argument and there are no pointers to references. Function types would be a bit more reasonable - I can at least form a pointer to a function to pass to construct_at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I was trying to put something in here that would indicate use of the new SFINAE rather than is_constructible... but maybe calling is_constructible would be correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can_construct_at is very clearly not is_constructible_v even without the void.
maybe calling
is_constructiblewould be correct?
Nope: it's very intentionally "if this new expression is well-formed" instead of is_constructible because the latter requires destructibility which the former does not. (I'm not a fan of this level of constraint minimality, but that's what we standardized.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced these reference tests with struct indestructible.
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Outdated
Show resolved
Hide resolved
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Outdated
Show resolved
Hide resolved
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Outdated
Show resolved
Hide resolved
| inline constexpr bool | ||
| can_construct_at_impl<void_t<decltype(construct_at(declval<Ty*>(), declval<Types>()...))>, Ty, Types...> = true; | ||
|
|
||
| template<class Ty, class... Types> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is failing clang-format. I recommend configuring your editor to format on save.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I can't use format-on-save because I spend too much time editing things that aren't the STL that are damaged when I do that :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm quite happy to have our CI yell at me :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using code . as
Line 4 in d4ee5c3
| "editor.formatOnSave": true, |
tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp
Show resolved
Hide resolved
|
Thanks again for your contribution! |
<memory> construct_at() (microsoft#501)
Thanks again for your changes and review! |
Description
A small and quite useful part of #37.
Checklist
Be sure you've read README.md and understand the scope of this repo.
If you're unsure about a box, leave it unchecked. A maintainer will help you.
_Uglyas perhttps://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
verified by an STL maintainer before automated testing is enabled on GitHub,
leave this unchecked for initial submission).
members, adding virtual functions, changing whether a type is an aggregate
or trivially copyable, etc.).
the C++ Working Draft (including any cited standards), other WG21 papers
(excluding reference implementations outside of proposed standard wording),
and LWG issues as reference material. If they were derived from a project
that's already listed in NOTICE.txt, that's fine, but please mention it.
If they were derived from any other project (including Boost and libc++,
which are not yet listed in NOTICE.txt), you must mention it here,
so we can determine whether the license is compatible and what else needs
to be done.