docs: address community issue feedback (#5 #338 #142 #246 #136 #303)

- const README: rewrite the space-saving claim per issue #5 follow-ups
  (constant-expression const vs #define immediates; which const qualify
  as constant expressions)
- const README: fix the class-section diagnosis per issue #338 (overload
  resolution picks the const overload; the restriction only surfaces
  once that overload is removed)
- sizeof README: virtual-inheritance result is compiler-dependent
  (GCC merges vbptr+vfptr -> 16, MSVC keeps them separate -> 32) #246
- static README: new section on internal linkage / access restriction
  with anonymous-namespace comparison #142
- 10-day practice: full problem list table + fixed day links #136
- new design_pattern/singleton/singleton_default.hpp: reusable
  thread-safe CRTP singleton template, compile+concurrency tested #303
This commit is contained in:
light-city
2026-10-13 19:23:54 +08:00
parent cfc9af1fcb
commit dfe1c933b3
159 changed files with 20461 additions and 182 deletions

70
tool/dbg-macro/README.md Normal file
View File

@@ -0,0 +1,70 @@
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-tools/dbg-macro/) 同步生成,网站版本含多语言与更新排版。
# C++ dbg-macro 调试宏
打日志是 C++ 开发中必不可少的一种 debug 方式,dbg-macro 受 Rust 语言中 的 `dbg` 启发,提供比 `printf` 和 `std::cout` 更好的宏函数。主要有如下特点:
- 美观的彩色输出(当输出不是交互式终端时,颜色将自动禁用)
- 兼容 C++11,并且是 header-only
- 支持基础类型和 STL 容器类型的输出
- 可以输出文件名、行号、函数名和原始表达式
例如下面的代码:
```cpp
#include <vector>
#include <dbg.h>
// You can use "dbg(..)" in expressions:
int factorial(int n) {
if (dbg(n <= 1)) {
return dbg(1);
} else {
return dbg(n * factorial(n - 1));
}
}
int main() {
std::string message = "hello";
dbg(message); // [example.cpp:15 (main)] message = "hello" (std::string)
const int a = 2;
const int b = dbg(3 * a) + 1; // [example.cpp:18 (main)] 3 * a = 6 (int)
std::vector<int> numbers{b, 13, 42};
dbg(numbers); // [example.cpp:21 (main)] numbers = {7, 13, 42} (size: 3) (std::vector<int>)
dbg("this line is executed"); // [example.cpp:23 (main)] this line is executed
factorial(4);
return 0;
}
```
效果如下:
![](https://camo.githubusercontent.com/3cde47c8db560b3ed42763f2ef306d78d4b19087/68747470733a2f2f692e696d6775722e636f6d2f4e4845596b39412e706e67)
## 安装
```bash
git clone https://github.com/sharkdp/dbg-macro
sudo ln -s $(readlink -f dbg-macro/dbg.h) /usr/include/dbg.h
```
这样,你就可以在任何地方使用 `dbg.h` 了。
### 在 Arch Linux 上
```bash
yay -S dbg-macro
```
### 使用 vcpkg
```bash
vcpkg install dbg-macro
```
更多内容详见 [官方文档](https://github.com/sharkdp/dbg-macro)。

118
tool/like_python/README.md Normal file
View File

@@ -0,0 +1,118 @@
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-tools/cpp-jupyter-notebook/) 同步生成,网站版本含多语言与更新排版。
# C++ Jupyter Notebook 交互
在Python中我们可以使用`Jupyter Notebook`直接看到结果,例如:
```c
l = [1,2]
l
```
直接输出:
```
[1,2]
```
那当使用C++的时候,例如:
```cpp
map<string, int> mp{
{"one", 1},
{"two", 2},
{"three", 3},
{"four", 4}
};
```
如果要输出,就得循环遍历,可否直接输出结果呢?
so easy!!! `Jupyter Notebook`可以解决一切问题,哈哈~
## 如何在Jupyter中玩C++?
在github上有一个仓库,如下所示:
> https://github.com/QuantStack/xeus-cling
`xeus-cling` 是一个用于C++的Jupyter内核,基于C++解释器和Jupyter协议xeus的原生实现。
目前,支持Mac与Linux,但不支持Windows。
安装也是非常简单,首先安装好Anaconda,在里面创建一个虚拟环境:
```
conda create -n cling
```
切换进去:
```
conda activate cling
```
给新环境安装`jupyter`和`notebook`
```
conda install jupyter notebook
```
使用`conda-forge`安装`xeus-cling`
```
conda install xeus-cling -c conda-forge
```
为了加速安装,请记得给Anaconda配置源!
检查是否安装好了内核(kernel):
```
jupyter kernelspec list
```
输出:
```cpp
python3 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp17
```
打开`Jupyter Notebook`,就可以看到看到kernel了。
启动`Jupyter Notebook`:
```
jupyter-notebook
```
## 如何在Jupyter中玩C?
只需要安装c kernel即可!
可以直接在当前环境中创建c kernel,也可以新开一个环境安装,下面是在当前环境中直接安装。
```
pip install jupyter-c-kernel
install_c_kernel
jupyter kernelspec list
```
此时,就输出:
```cpp
c /home/light/anaconda3/envs/cling/share/jupyter/kernels/c
python3 /home/light/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp17
```
启动`Jupyter Notebook`:
```
jupyter-notebook
```

5
tool/look/README.md Normal file
View File

@@ -0,0 +1,5 @@
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-tools/cpp-insights/) 同步生成,网站版本含多语言与更新排版。
# C++ Insights 编译期观察
- [C++ Insights — 查看编译器眼中的代码](https://cppinsights.io/)

23
tool/output/README.md Normal file
View File

@@ -0,0 +1,23 @@
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-tools/stl-container-output/) 同步生成,网站版本含多语言与更新排版。
# C++ STL 容器快捷输出
对吴老师的代码进行了修改,[点击此处直通代码](https://github.com/Light-City/CPlusPlusThings/tree/master/tool/output/output_container.h)
输入:
```cpp
map<int, int> mp{
{1, 1},
{2, 4},
{3, 9}};
cout << mp << endl;
```
输出结果显示:
```cpp
{ 1 => 1, 2 => 4, 3 => 9 }
```
####