Skip to content

Conversation

@AdamBucior
Copy link
Contributor

@AdamBucior AdamBucior commented Feb 13, 2020

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.

  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
  • The STL builds successfully and all tests have passed (must be manually
    verified by an STL maintainer before automated testing is enabled on GitHub,
    leave this unchecked for initial submission).
  • These changes introduce no known ABI breaks (adding members, renaming
    members, adding virtual functions, changing whether a type is an aggregate
    or trivially copyable, etc.).
  • These changes were written from scratch using only this repository,
    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.

@AdamBucior AdamBucior requested a review from a team as a code owner February 13, 2020 20:05
@BillyONeal
Copy link
Member

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.

@AdamBucior
Copy link
Contributor Author

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 constexpr unconditionally even though none of the compilers supports constexpr new yet? Or should I place there /* constexpr */ comment? I think I don't understand.

@BillyONeal
Copy link
Member

I would not declare constexpr anything here.

@BillyONeal
Copy link
Member

@AdamBucior Are you happy with my changes?

@AdamBucior
Copy link
Contributor Author

Yes, thanks!

@BillyONeal
Copy link
Member

I might be pedantic here but it greatly improves readability if there is a space before the noexcepts so that they align with the false tests

static_assert( noexcept(std::construct_at(std::declval<int*>(), 42)));
static_assert(!noexcept(std::construct_at(std::declval<std::string*>(), "hello")));

clang-format hates this.


struct X {};

template <class _Void, class Ty, class... Types>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_Ugly.

Suggested change
template <class _Void, class Ty, class... Types>
template <class Void, class Ty, class... Types>

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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_constructible would 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.)

Copy link
Member

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.

inline constexpr bool
can_construct_at_impl<void_t<decltype(construct_at(declval<Ty*>(), declval<Types>()...))>, Ty, Types...> = true;

template<class Ty, class... Types>
Copy link
Member

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.

Copy link
Member

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 :(

Copy link
Member

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 :) )

Copy link
Member

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

"editor.formatOnSave": true,
will set format-on-save for just this workspace.

@BillyONeal BillyONeal merged commit a092e67 into microsoft:master Feb 29, 2020
@BillyONeal
Copy link
Member

Thanks again for your contribution!

fengjixuchui added a commit to fengjixuchui/STL that referenced this pull request Feb 29, 2020
@AdamBucior
Copy link
Contributor Author

Thanks again for your contribution!

Thanks again for your changes and review!

@AdamBucior AdamBucior deleted the construct_at branch February 29, 2020 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx20 C++20 feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants