From b351907510403ca5051e2f2e1ca23649c09e3a2b Mon Sep 17 00:00:00 2001 From: Ted Mosly Date: Fri, 2 Sep 2022 21:26:24 +0800 Subject: [PATCH 1/4] 79 draft --- posts/079.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 posts/079.md diff --git a/posts/079.md b/posts/079.md new file mode 100644 index 0000000..a92a658 --- /dev/null +++ b/posts/079.md @@ -0,0 +1,60 @@ +--- +layout: post +title: 第79期 +--- +# C++ 中文周刊 第79期 + +`TODO add README then remove this line` + +从[reddit](https://www.reddit.com/r/cpp/)/[hackernews](https://news.ycombinator.com/)/[lobsters](https://lobste.rs/)/[meetingcpp](https://www.meetingcpp.com/blog/blogroll/)/[purecpp](http://www.purecpp.cn/)知乎等等摘抄一些c++动态 + +`TODO fix meetingcpp blogroll link` + +[周刊项目地址](https://github.com/wanghenshui/cppweeklynews)|[在线地址](https://wanghenshui.github.io/cppweeklynews/) |[知乎专栏](https://www.zhihu.com/column/jieyaren) |[腾讯云+社区](https://cloud.tencent.com/developer/column/92884) + +弄了个qq频道,[手机qq点击进入](https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=xzjHQ&from=246610&biz=ka) + +欢迎投稿,推荐或自荐文章/软件/资源等 + +`TODO update draft name` + +可以贴在下一期草稿里 [草稿链接](https://github.com/wanghenshui/cppweeklynews/pull/79.md) + +`TODO update date here` + +--- + +## 资讯 + +标准委员会动态/ide/编译器信息放在这里 + +[编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-01-05 第131期](https://github.com/hellogcc/osdt-weekly/blob/master/weekly-2022/2022-01-05.md) + +`TODO fix link then remove this line` + +## 文章 + +- [c++ tip of week ](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/) + +`TODO fix link then remove this line` + +## 视频 + +- [C++ Weekly ](https://www.youtube.com/channel/UCxHAlbZQNFU2LgEtiqd2Maw) + +`TODO fix link then remove this line` + +## 开源项目需要人手 + +- [asteria](https://github.com/lhmouse/asteria) 一个脚本语言,可嵌入,长期找人,希望胖友们帮帮忙,也可以加群384042845和作者对线 +- [pika](https://github.com/OpenAtomFoundation/pika) 一个nosql 存储, redis over rocksdb,非常需要人贡献代码胖友们, 感兴趣的欢迎加群294254078前来对线 + +## 新项目介绍/版本更新 + +## 工作招聘 + +--- + +看到这里或许你有建议或者疑问或者指出错误,请留言评论! 多谢! 你的评论非常重要!也可以帮忙点赞收藏转发!多谢支持! + +[本文永久链接](https://wanghenshui.github.io/cppweeklynews/posts/079.html) From 9edef4a7994ebfc79375f7c61ad46374bae35622 Mon Sep 17 00:00:00 2001 From: Ted Mosly Date: Wed, 7 Sep 2022 14:30:53 +0800 Subject: [PATCH 2/4] 79 v0 with some fix --- README.md | 2 +- posts/078.md | 18 ++++-- posts/079.md | 152 ++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 157 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e8931d7..f6c5a29 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ RSS使用仓库的release RSS [链接](https://github.com/wanghenshui/cppweeklyn | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | --------------------- | | [五十一](./posts/051.md) | [五十二](./posts/052.md) | [五十三](./posts/053.md) | [五十四](./posts/054.md) | [五十五](./posts/055.md) | [五十六](./posts/056.md) | [五十七](./posts/057.md) | [五十八](./posts/058.md) | [五十九](./posts/059.md) | [六十期](./posts/060.md) | | [六十一](./posts/061.md) | [六十二](./posts/062.md) | [六十三](./posts/063.md) | [六十四](./posts/064.md) | [六十五](./posts/065.md) | [六十六](./posts/066.md) | [六十七](./posts/067.md) | [六十八](./posts/068.md) | [六十九](./posts/069.md) | [七十期](./posts/070.md) | -| [七十一](./posts/071.md) |[七十二](./posts/072.md)|[七十三](./posts/073.md)|[七十四](./posts/074.md)|[七十五](./posts/075.md)|[七十六](./posts/076.md)|[七十七](./posts/077.md)|[七十八](./posts/078.md)||| +| [七十一](./posts/071.md) |[七十二](./posts/072.md)|[七十三](./posts/073.md)|[七十四](./posts/074.md)|[七十五](./posts/075.md)|[七十六](./posts/076.md)|[七十七](./posts/077.md)|[七十八](./posts/078.md)|[七十九](./posts/079.md)|| --- diff --git a/posts/078.md b/posts/078.md index b9d31da..f279c49 100644 --- a/posts/078.md +++ b/posts/078.md @@ -4,10 +4,8 @@ title: 第78期 --- # C++ 中文周刊 第78期 - 从[reddit](https://www.reddit.com/r/cpp/)/[hackernews](https://news.ycombinator.com/)/[lobsters](https://lobste.rs/)/[meetingcpp](https://www.meetingcpp.com/blog/blogroll/items/Meeting-Cpp-weekly-Blogroll-344.html)摘抄一些c++动态 - [周刊项目地址](https://github.com/wanghenshui/cppweeklynews)|[在线地址](https://wanghenshui.github.io/cppweeklynews/) |[知乎专栏](https://www.zhihu.com/column/jieyaren) |[腾讯云+社区](https://cloud.tencent.com/developer/column/92884) 弄了个qq频道,[手机qq点击进入](https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=xzjHQ&from=246610&biz=ka) @@ -16,7 +14,7 @@ title: 第78期 可以贴在下一期草稿里 [草稿链接](https://github.com/wanghenshui/cppweeklynews/pull/9) -2020 09 02 +2022 09 02 --- @@ -26,7 +24,6 @@ title: 第78期 [编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-08-31 第165期](https://github.com/hellogcc/osdt-weekly/blob/master/weekly-2022/2022-08-31.md) - ## 文章 - [What is the “vector pessimization”?](https://quuxplusone.github.io/blog/2022/08/26/vector-pessimization/) @@ -34,6 +31,7 @@ title: 第78期 尽量让move 构造函数 noexcept, 不然用vector可能有问题,多copy 比如这个 + ```cpp struct Instrument { int n_; @@ -63,6 +61,11 @@ vector本身的搬迁move的多余动作,如果能nothrow,move就更简单 free没有size看上去是个巧妙的设计,实际上隐含了挺多脏活 + +实际上,malloc/free/realloc等等,这些api还是太低层太精细了。对于使用者心理负担很大。 + +感谢@lh_mouse补充 + - [C++ Coroutines: Understanding the Compiler Transform](https://lewissbaker.github.io/2022/08/27/understanding-the-compiler-transform) 协程背后都做了啥 @@ -88,6 +91,7 @@ int main(int, char** argv){ fn2(); // ignoring return value with [[nodiscard]] } ``` + - [Do we need the Y-combinator in C++? ](http://ib-krajewski.blogspot.com/2017/10/do-we-need-y-combinator-in-c-and.html?m=1) 老文,科普一下概念。 @@ -95,6 +99,7 @@ int main(int, char** argv){ - [constexpr Function Parameters](https://www.elbeno.com/blog/?p=1685) 参数不是constexpr + ```cpp consteval auto square(int x) -> int { return x * x; } @@ -105,7 +110,6 @@ constexpr auto twice_square(int x) -> int { return square(x); } - [实现一个trivially_copyable的tuple ](http://www.purecpp.cn/detail?id=2309) - [并发与异步执行流中的对象角色概述(一) ](http://www.purecpp.cn/detail?id=2310) - - [编程语言-从来如此的便是对吗?](https://zhuanlan.zhihu.com/p/558778083) 看个乐 @@ -123,6 +127,7 @@ constexpr auto twice_square(int x) -> int { return square(x); } - [Why am I getting a null pointer crash when trying to call a method on my C++/WinRT object?](https://devblogs.microsoft.com/oldnewthing/20220901-00/?p=107097) 为什么大哥解bug这么熟练 + ## 视频 - [C++ Weekly - Ep 339 - `static constexpr` vs `inline constexpr`](https://www.youtube.com/watch?v=QVHwOOrSh3w) @@ -131,6 +136,9 @@ static constexpr 和 inline constexpr区别。inline constexpr能合并文件重 聪明的你想到了static inline constexpr。这个效果就是static constexpr。static限制了范围 +当然,-fmerge-contants能从另一个层面解决这个问题 + +感谢@lh_mouse补充 ## 开源项目需要人手 diff --git a/posts/079.md b/posts/079.md index a92a658..655a9d2 100644 --- a/posts/079.md +++ b/posts/079.md @@ -4,7 +4,6 @@ title: 第79期 --- # C++ 中文周刊 第79期 -`TODO add README then remove this line` 从[reddit](https://www.reddit.com/r/cpp/)/[hackernews](https://news.ycombinator.com/)/[lobsters](https://lobste.rs/)/[meetingcpp](https://www.meetingcpp.com/blog/blogroll/)/[purecpp](http://www.purecpp.cn/)知乎等等摘抄一些c++动态 @@ -16,28 +15,163 @@ title: 第79期 欢迎投稿,推荐或自荐文章/软件/资源等 -`TODO update draft name` -可以贴在下一期草稿里 [草稿链接](https://github.com/wanghenshui/cppweeklynews/pull/79.md) - -`TODO update date here` +可以贴在下一期草稿里 [草稿链接](https://github.com/wanghenshui/cppweeklynews/pull/10.md) +2022 0909 --- ## 资讯 标准委员会动态/ide/编译器信息放在这里 +llvm 15发布了。c++20支持等等一大堆修改 + +[lld 15 ELF changes ](https://maskray.me/blog/2022-09-05-lld-15-elf-changes) + [编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-01-05 第131期](https://github.com/hellogcc/osdt-weekly/blob/master/weekly-2022/2022-01-05.md) `TODO fix link then remove this line` ## 文章 -- [c++ tip of week ](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/) - -`TODO fix link then remove this line` - +- [Did you know that with C++20 (constexpr containers) TMP can be achieved with STL ](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/) + +```cpp +#include + +template +auto slice = List + | std::ranges::views::drop(Begin) + | std::ranges::views::take(End); + +static_assert( + slice<1_c, 2_c, boost::mp::list()> + == + boost::mp::list()); +``` + +typelist实现更简单了。恐怖 + +- [A moved from optional](https://akrzemi1.wordpress.com/2022/09/06/a-moved-from-optional/) + +optinal的move并不会真正的move T, 让T为无效value + +```cpp +template +void test(T v) +{ + optional o = v; + assert (o); // o contains a value + optional p = std::move(o); + assert (o); // o still contains a value! +} +``` +完全取决于T的move,optional会保留T的壳子。 + +比如unique_ptr + +```cpp +int * p = new int(1); + +optional> op = unique_ptr(p); +assert (op); +assert (op->get() == p); + +optional> o2 = std::move(op); +assert (op); // still contains a value +assert (op->get() == nullptr); // the value is moved from +assert (o2); +assert (o2->get() == p); +``` +unique_ptr内部会搬走,但本身是还在optional里的。这样实现更快,对于trival类型,这样优化的可以直接memcpy,更高效一些 +大概实现成这个样子 + +```cpp +template +class optional +{ + bool _is_initialized; + Trivial _value; + + optional() : _is_initialized(false) {} + // use defaulted copy and move +}; +``` + +- [Using std::unique_ptr With C APIs](https://eklitzke.org/use-unique-ptr-with-c-apis) + +```cpp +// Second argument is a pointer to the type of std::fclose, we could also have +// written it out explicitly as std::unique_ptr. +using FilePtr = std::unique_ptr; + +// Instantiate the FILE* with the destructor we want. +FilePtr file(std::fopen(filename, "rbe"), std::fclose); + +// Do stuff with the file +std::fread(buf_.data(), 1, buf_.size(), file.get()); +``` + +比写个deferGuard能更干净些 + +```cpp +using XXH3StatePtr = std::unique_ptr; +XXH3StatePtr state(XXH3_createState(), XXh3_freeState); +``` +但这种写法的问题在于,需要判定创建失败/指针是否有效 + + +- [C++23’s new function syntax](https://www.elbeno.com/blog/?p=1696) + +一个简单的函数 + +```cpp +[[nodiscard]] auto say_a_to( + std::string_view what, std::string_view name) -> std::string { + return std::string{what} + ", " + std::string{name} + "!"; +} + +say_a_to("Hi", "Kate"); // -> "Hi, Kate!" + +struct { + [[nodiscard]] auto operator()( + std::string_view what, std::string_view name) const -> std::string { + return std::string{what} + ", " + std::string{name} + "!"; + } +} say_b_to; + +say_b_to("Hello", "Tony"); // -> "Hello, Tony!" +``` + +没啥新奇的,但是c++23支持多维数组了,所以说`operator[]` 也算是一种函数了 + +比如 +```cpp + + +struct { + [[nodiscard]] auto operator[]( + std::string_view what, std::string_view name) const -> std::string { + return std::string{what} + ", " + std::string{name} + "!"; + } +} say_d_to; + +say_d_to["Goodbye", "Tony"]; // -> "Goodbye, Tony!" +``` + +```cpp +struct { + template + [[nodiscard]] auto operator[](Ts... ts) const noexcept { + return (0 + ... + ts); + } +} sum; +const auto s1 = sum[1, 2, 3]; // 6 +const auto s2 = sum[]; // 0 +``` + +我只能说看个乐,别这么写求求了 ## 视频 - [C++ Weekly ](https://www.youtube.com/channel/UCxHAlbZQNFU2LgEtiqd2Maw) From c16ddcb4fb178b2240fab7cef48c666b5a0d2581 Mon Sep 17 00:00:00 2001 From: Ted Mosly Date: Wed, 7 Sep 2022 16:34:37 +0800 Subject: [PATCH 3/4] update --- posts/079.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/posts/079.md b/posts/079.md index 655a9d2..9cb82e1 100644 --- a/posts/079.md +++ b/posts/079.md @@ -35,6 +35,22 @@ llvm 15发布了。c++20支持等等一大堆修改 ## 文章 +- [用户态操作系统之四 Seastar的init函数与stop](https://zhuanlan.zhihu.com/p/561202708) +- [用户态操作系统之五 Seastar的timer](https://zhuanlan.zhihu.com/p/561214124) +- [用户态操作系统之六 Seastar的跨线程通信](https://zhuanlan.zhihu.com/p/561511141) + +seastar的一些代码走读。可以看看 + +- [C++-模板-萃取的实现(三)](https://www.zhihu.com/column/c_1523802493980569601) + +其实就是编译期检测接口的能力 + +- [C++ 20 协程 Coroutine(1,基础)](https://zhuanlan.zhihu.com/p/561623494) +- [C++ 20 协程 Coroutine(2,等待体)](https://zhuanlan.zhihu.com/p/561864514) +- [C++ 20 协程 Coroutine(3,剖析)](https://zhuanlan.zhihu.com/p/561884301) + +一组协程教程 + - [Did you know that with C++20 (constexpr containers) TMP can be achieved with STL ](https://github.com/QuantlabFinancial/cpp_tip_of_the_week/) ```cpp From 2668577172d72c432de08f016b17f388af288599 Mon Sep 17 00:00:00 2001 From: Ted Mosly Date: Thu, 8 Sep 2022 14:26:41 +0800 Subject: [PATCH 4/4] 79 v1 --- posts/079.md | 56 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/posts/079.md b/posts/079.md index 9cb82e1..fdfee99 100644 --- a/posts/079.md +++ b/posts/079.md @@ -5,9 +5,8 @@ title: 第79期 # C++ 中文周刊 第79期 -从[reddit](https://www.reddit.com/r/cpp/)/[hackernews](https://news.ycombinator.com/)/[lobsters](https://lobste.rs/)/[meetingcpp](https://www.meetingcpp.com/blog/blogroll/)/[purecpp](http://www.purecpp.cn/)知乎等等摘抄一些c++动态 +从[reddit](https://www.reddit.com/r/cpp/)/[hackernews](https://news.ycombinator.com/)/[lobsters](https://lobste.rs/)/[purecpp](http://www.purecpp.cn/)知乎等等摘抄一些c++动态 -`TODO fix meetingcpp blogroll link` [周刊项目地址](https://github.com/wanghenshui/cppweeklynews)|[在线地址](https://wanghenshui.github.io/cppweeklynews/) |[知乎专栏](https://www.zhihu.com/column/jieyaren) |[腾讯云+社区](https://cloud.tencent.com/developer/column/92884) @@ -18,7 +17,7 @@ title: 第79期 可以贴在下一期草稿里 [草稿链接](https://github.com/wanghenshui/cppweeklynews/pull/10.md) -2022 0909 +2022 0908 提前发了。周五有事 --- ## 资讯 @@ -29,12 +28,30 @@ llvm 15发布了。c++20支持等等一大堆修改 [lld 15 ELF changes ](https://maskray.me/blog/2022-09-05-lld-15-elf-changes) -[编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-01-05 第131期](https://github.com/hellogcc/osdt-weekly/blob/master/weekly-2022/2022-01-05.md) +[编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-09-07 第166期](https://github.com/hellogcc/osdt-weekly/blob/master/weekly-2022/2022-09-07.md) -`TODO fix link then remove this line` ## 文章 +- [使用协程需要注意的问题(一) ](http://www.purecpp.cn/detail?id=2313) + +要注意协程被线程切换影响 + +- [C++23特性总结 - 上](https://zhuanlan.zhihu.com/p/562383157) +- [C++23特性总结 - 下](https://zhuanlan.zhihu.com/p/562383556) + +c++23详细总结 + +- [使用 C++ 20 协程封装 RDMA 操作](https://zhuanlan.zhihu.com/p/553140760) +- [使用 C++ 20 协程封装 UCX](https://zhuanlan.zhihu.com/p/555971343) + +c++20应用协程举例 + +- [STL源码分析之std::function](https://zhuanlan.zhihu.com/p/560964284) +- [g++8.3,sizeof(std::function)为什么等于32](https://www.zhihu.com/question/530797704/answer/2658642917) + +std::function的分析 + - [用户态操作系统之四 Seastar的init函数与stop](https://zhuanlan.zhihu.com/p/561202708) - [用户态操作系统之五 Seastar的timer](https://zhuanlan.zhihu.com/p/561214124) - [用户态操作系统之六 Seastar的跨线程通信](https://zhuanlan.zhihu.com/p/561511141) @@ -100,6 +117,7 @@ assert (op->get() == nullptr); // the value is moved from assert (o2); assert (o2->get() == p); ``` + unique_ptr内部会搬走,但本身是还在optional里的。这样实现更快,对于trival类型,这样优化的可以直接memcpy,更高效一些 大概实现成这个样子 @@ -190,19 +208,39 @@ const auto s2 = sum[]; // 0 我只能说看个乐,别这么写求求了 ## 视频 -- [C++ Weekly ](https://www.youtube.com/channel/UCxHAlbZQNFU2LgEtiqd2Maw) +- [C++ Weekly - Ep 340 - Finally! A Simple String Split in C++! ](https://www.youtube.com/watch?v=V14xGZAyVKI) -`TODO fix link then remove this line` +```cpp +#include +#include +#include + +int main() { + + // this is lazily evaluated + auto strings = std::string_view{"Hello C++ 20"} | std::views::split(' '); + + // the result is a range of ranges + + for (const auto &ref : strings) { + // C++ 20 + std::cout << '\n' << std::string_view{ref.begin(), ref.end()}; + // C++ 23 + std::cout << '\n' << std::string_view{ref}; + } +} +``` ## 开源项目需要人手 - [asteria](https://github.com/lhmouse/asteria) 一个脚本语言,可嵌入,长期找人,希望胖友们帮帮忙,也可以加群384042845和作者对线 - [pika](https://github.com/OpenAtomFoundation/pika) 一个nosql 存储, redis over rocksdb,非常需要人贡献代码胖友们, 感兴趣的欢迎加群294254078前来对线 -## 新项目介绍/版本更新 - ## 工作招聘 +寒冬了 + +华为出新手机了,但我不买,因为想把寒冬传给它 --- 看到这里或许你有建议或者疑问或者指出错误,请留言评论! 多谢! 你的评论非常重要!也可以帮忙点赞收藏转发!多谢支持!