-
Notifications
You must be signed in to change notification settings - Fork 137
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
最卢的瑟's homework #312
最卢的瑟's homework #312
Conversation
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.
CI 没过。
src/群友提交/第05题/brian.cpp
Outdated
* @brief https://en.cppreference.com/w/cpp/utility/functional/invoke | ||
* invoke: 如果\p func 是成员函数, 则\p ...args 的第一个参数是对应的对象(\p &,* ) | ||
*/ | ||
std::invoke(std::forward<F>(func), args...); |
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.
你 args...
不写成完美转发 std::forward<A>(args)...
是为什么?
src/群友提交/第06题/brian.md
Outdated
@@ -0,0 +1,3 @@ | |||
为保证 atomic 对象的原子性,复制和移动都是不允许的。 | |||
C++17之前 `std::atomic<int> n = 6;` 不合法是因为 atomic 只支持列表初始化, 写成 `std::atomic<int> n = {6};` 就可以通过编译了。 |
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.
其实和这句话基本没啥关系
src/群友提交/第06题/brian.md
Outdated
@@ -0,0 +1,3 @@ | |||
为保证 atomic 对象的原子性,复制和移动都是不允许的。 | |||
C++17之前 `std::atomic<int> n = 6;` 不合法是因为 atomic 只支持列表初始化, 写成 `std::atomic<int> n = {6};` 就可以通过编译了。 | |||
17+之后的 `std::atomic<int> n = 6;` 其实是原地构造,也不涉及任何复制移动,合法。 |
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.
你应该聊 RVO 的事情。
C++17 RVO 只有两种情况:
- 同类型临时对象初始化
- return 临时量
这里显然是 同类型临时对象初始化,你看其他答案或者解析吧
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.
如上
src/群友提交/第06题/brian.md
Outdated
在C++17及之后 `std::atomic<int> n = 6;` 可以通过编译,主要是因为C++17引入了对复制消除的强制要求, | ||
允许从基础类型直接初始化 `std::atomic` 对象, 即使 `std::atomic<int>` 的复制构造函数被删除。 | ||
|
||
在C++17之前, 这种初始化因为尝试调用被删除的复制构造函数而失败。 |
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.
还是不对,你看标准答案去吧。
src/群友提交/第06题/brian.md
Outdated
允许从基础类型直接初始化 `std::atomic` 对象, 即使 `std::atomic<int>` 的复制构造函数被删除。 | ||
|
||
在C++17之前, 这种初始化因为尝试调用被删除的复制构造函数而失败。 | ||
这个例子其实展示的是C++17改进了直接初始化和复制消除的规则,而不是传统意义上的RVO。 |
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.
与初始化本身没啥关系
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.
好的👌 国王万岁
@Mq-b 你这 review 的也太难受了,一个 review 里可以有很多个 comment,你非要每个都 comment 一次。 |
@Mq-b 另外你如果要合并,一定要用 Squash and merge(那个又大又绿的合并按钮右侧有个倒三角,点它就能改 method)。这么一条 commit tree 如果进了仓库,那就是在糟蹋提交记录。 |
请国王查收