C++ 中文周刊 第145期

周刊项目地址

公众号

qq群 点击进入

RSS https://github.com/wanghenshui/cppweeklynews/releases.atom

欢迎投稿,推荐或自荐文章/软件/资源等评论区留言

本期文章由 黄亮Anthony HNY 赞助

2024 01 07


资讯

标准委员会动态/ide/编译器信息放在这里

编译器信息最新动态推荐关注hellogcc公众号 本周更新 2024-01-03 第235期

文章

现代分支预测:从学术界到工业界

看个乐呵, 了解概念对于CPU运行还是有点理解的

LLVM中指令选择的流程是啥样的?

LLVM知识,学吧,都是知识,早晚碰到

【数据结构】Jemalloc中的Radix Tree

解析Jemalloc的关键数据结构

jemalloc最新知识,学吧

Optimizing the unoptimizable: a journey to faster C++ compile times

编译很慢,怎么抓?

#include <fmt/core.h>

int main() {
  fmt::print("Hello, {}!\n", "world");
}
// c++ -ftime-trace -c hello.cc -I include -std=c++20

ftime-trace的数据可以放到浏览器的tracing里,比如 chrome://tracing/

firefox可以用这个 https://profiler.firefox.com/from-url/https%3A%2F%2Fvitaut.net%2Ffiles%2F2024-hello-before.json/marker-chart/?globalTrackOrder=0&hiddenLocalTracksByPid=65312-fwx3&thread=0&timelineType=category&v=10

我没看懂他是怎么分析出头文件的耗时的,总之,把string前向声明一下


#ifdef FMT_BEGIN_NAMESPACE_STD
FMT_BEGIN_NAMESPACE_STD
template <typename Char>
struct char_traits;
template <typename T>
class allocator;
template <typename Char, typename Traits, typename Allocator>
class basic_string;
FMT_END_NAMESPACE_STD
#else
# include <string>
#endif

但是这种接口编译不过


template <typename... T>
 FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
    -> basic_string<char> {
   return vformat(fmt, fmt::make_format_args(args...));
 }

因为basic_string<char>找不到实现,怎么破?

template <typename... T, typename Char = char>
 FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
    -> basic_string<Char> {
   return vformat(fmt, fmt::make_format_args(args...));
 }

然后这个操作就省掉了大量编译时间

[Why doesn’t my code compile when I change a shared_ptr(p) to an equivalent make_shared(p)?](https://devblogs.microsoft.com/oldnewthing/20240103-00/?p=109228)

结构是这样的

class WidgetContainer : IWidgetCallback
{
    //    
};

    auto widget = std::shared_ptr<Widget>(new Widget(this));

能不能换成make_shared?不能,因为是private继承

怎么破?


    auto widget = std::make_shared<Widget>(
        static_cast<IWidgetCallback*>(this));

Did you know about C++26 static reflection proposal (2/N)?

struct foo {
  int a{};
  int b{};
  int c{};
};

static_assert(3 == std::size(std::meta::nonstatic_data_members_of(^foo)));

Inside STL: The deque, implementation

deque msvc实现有坑爹的地方

  gcc clang msvc
Block size as many as fit in 512 bytes but at least 1 element as many as fit in 4096 bytes but at least 16 elements power of 2 that fits in 16 bytes but at least 1 element
Initial map size 8 2 8
Map growth
Map shrinkage On request On request On request
Initial first/last Center Start Start
Members block** map; size_t map_size;
iterator first;
iterator last;
block** map;
block** first_block;
block** last_block;
block** end_block;
size_t first;
size_t size;
block** map; size_t map_size;
size_t first;
size_t size;
Map layout counted array simple_deque counted array
Valid range Pair of iterators Start and count Start and count
Iterator T* current;
T* current_block_begin;
T* current_block_end;
block** current_block;
T* current; block** current_block; deque* parent;
size_t index;
begin()/end() Copy first and last. Break first and first + size into block index and offset. Break first and first + size into block index and offset.
Spare blocks Aggressively pruned Keep one on each end Keep all

block size太小了

windows相关

视频

What we’ve been (a)waiting for? - Hana Dusíková - Meeting C++ 2023

介绍协程并写了个co curl 有点意思,视频我也传B站了 https://www.bilibili.com/video/BV1NG411B7Fy/

代码在这里 https://github.com/hanickadot/co_curl

开源项目更新/新项目介绍

#include <fmt/chrono.h>

int main() {
  fmt::print("{}\n", std::chrono::days(42)); // prints "42d"
}

编译期物理计算的

工作招聘

https://job.toutiao.com/s/i8Tv36Jf 字节杭州虚拟机v8研发

字节的音视频团队,主要负责剪映上的音视频/非线性编辑相关工作,业务前景也比较好,目前有三个方向的岗位

base北上广深杭都可以,薪资open,有兴趣的同学可以通过链接投递

互动环节

新的一年开始了,本周刊也走过了三个年头,希望大家都健康我也继续保持更新下去


本文永久链接

如果有疑问评论最好在上面链接到评论区里评论,这样方便搜索,微信公众号有点封闭/知乎吞评论

看到这里或许你有建议或者疑问或者指出错误,请留言评论! 多谢! 你的评论非常重要!也可以帮忙点赞收藏转发!多谢支持! 觉得写的不错那就给点吧, 在线乞讨 微信转账