Skip to content

败犬日报 2024-11-12

1. std::string::data() 在 C++17 以及更早只有 const

17 以及更早只返回 const char*,20 之后有返回 char * 的版本。

不同的是 std::vector 一直都有可变版本的 data。

2. std::launder, 隐式生存期

https://zhuanlan.zhihu.com/p/6478575351?utm_psn=1839749251762110464

3. 打开一个大概 15G 的文本文件

可选的工具:less, emacs。

4. 浮点数求和,double 精度不够

可以试试 long double、Pairwise 求和Kahan 求和

5. 1ull<<100,左移或右移超出位数

是未定义行为。

https://zh.cppreference.com/w/cpp/language/operator_arithmetic

任何情况下,如果右操作数的值为负或不小于左操作数中的位数,那么行为未定义。