前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++ 中文周刊 第96期

C++ 中文周刊 第96期

作者头像
王很水
发布2023-01-14 10:20:24
2380
发布2023-01-14 10:20:24
举报

C++ 中文周刊 第96期

周刊项目地址

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

弄了个qq频道,手机qq点击进入

欢迎投稿,推荐或自荐文章/软件/资源等

提交 issue

0113

部门聚餐了延误了一下。本周没看视频

资讯

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

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

一个博客收集网站 https://swedencpp.se/blogs 英文c++的最新博客收集

文章

取对数

哎。倒腾cmake我头疼

有点意思。这种针对牛逼网卡的优化我感觉大厂都在做类似的玩意

又一个c++项目引入rust的。之前有火狐浏览器,clickhouse, redpanda,linux内核,唱衰一波,不过不要慌,c++程序员一时半会不会失业

看代码

代码语言:javascript
复制
constexpr auto get = [](auto value) {
  if consteval {
    return value;
  } else {
    auto result = 0;
    asm("movl $42, %%eax\n" : "=r" (result) );
    return result;
  }
};

static_assert(0 == get(0));
static_assert(4 == get(4));
static_assert(2 == get(2));

consteval auto fn() {
    return get(0);
}

int main(int argc, char**) {
  assert(42 == get(0));
  assert(42 == get(argc));
  return fn();
}

希望大家身体健康,活得久一点,就能用到静态反射了

编译器标准库用到很多变量是两个下划线 下划线大写字母开头的。自己定义变量尽量别用

测了一下simdutdf在Zen4的表现,挺强的

blake3是不是就是simd加速的?

给oilshell设计的GC。没仔细看

optional做函数参数是十分不恰当的。这玩意只适合做返回值

QVarLengthArray类似vector,区别在于对小数据做SBO优化,且resize不会做额外的初始化动作。初始化动作是c++默认有的。很多场景来看是多余的,比如string。c++20/23做了许多修正

比如

代码语言:javascript
复制
std::unique_ptr<int[]> p3 = std::make_unique_for_overwrite<int[]>(100'000);

再比如string

代码语言:javascript
复制
// C++23
std::string s = ~~~;
 
auto oldSize = s.size();
 
s.resize_and_overwrite(100'000, [oldSize](char *buf, std::size_t count) {
 
  // For starters, s will *reserve* enough space, without initializing it.
  //
  // - buf points to the string's storage (i.e. s.data()) *after* the reserve;
  // - count is the 1st argument to resize_and_overwrite (100k), so
  //   we can re-use this function with different `count`s.
 
 
  // Populate the range [buf, buf+count]. We can mutate the entirety of
  // the string's buffer. But let's say we're just interested in populating
  // the new contents -- from position oldSize up to count.
  for (size_it i = oldSize; i < count; ++i)
    buf[i] = generateData(i);
 
  // Notes:
  // - If we're growing, the newly created storage is *uninitialized*.
  //   Don't read from it!
  //
  // - The old contents are still there, and we can access them freely.
  //   If needed, carry `oldSize` manually, to identify where to start 
  //   writing (and leave the old contents alone).
  //
  // - It is legal to write into buf[count],
  //   but it will be overwritten with \0 when we're done.
     
  // We don't need to populate the *entire* buffer -- we may stop short!
  // The returned value will be the new size of the string.
 
  return actual_new_size;
});

QVarLengthArray不会做多余的初始化,请注意(不过QT这套东西会玩的越来越少了,大部分读者应该不玩QT)

基础知识,不会的可以去看《程序员的自我修养 链接/库》这本书

MSVC有两套coroutine API

代码语言:javascript
复制
// in <experimental/coroutine>
#ifndef _ALLOW_COROUTINE_ABI_MISMATCH
#pragma detect_mismatch("_COROUTINE_ABI", "1")
#endif // _ALLOW_COROUTINE_ABI_MISMATCH

// in <coroutine>
#ifndef _ALLOW_COROUTINE_ABI_MISMATCH
#pragma detect_mismatch("_COROUTINE_ABI", "2")
#endif // _ALLOW_COROUTINE_ABI_MISMATCH

使用 /std:c++20/std:c++latest,才会用最新的api,experimental是c++17旧的

又是Windows API,如何处理flags,我直接贴下面,不懂windows

Flag

Meaning

Recommendation

DISCONNECTED

No network interface detects any network

Treat as offline.

NOTRAFFIC

An interface is connected, but it cannot send or receive network traffic.

Treat as offline.

SUBNET/LOCALNETWORK

An interface has been configured to send traffic, but the system cannot confirm Internet connectivity.

Make one attempt to contact service.

INTERNET

The system has confirmed access to Microsoft Internet sites.

Treat as fully online.

没看懂

视频

没啥说的,之前讲过,#embed可以嵌入二进制,比如插个音乐,文本等等

开源项目需要人手

  • asteria 一个脚本语言,可嵌入,长期找人,希望胖友们帮帮忙,也可以加群384042845和作者对线
  • pika 一个nosql 存储, redis over rocksdb,非常需要人贡献代码胖友们, 感兴趣的欢迎加群294254078前来对线

新项目介绍/版本更新

没看懂这玩意是干什么的

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • C++ 中文周刊 第96期
    • 资讯
      • 文章
        • 视频
          • 开源项目需要人手
            • 新项目介绍/版本更新
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档