Skip to content

败犬日报 2025-07-10

1. const_cast 什么场景下必须用

一种是上游或下游不提供非 const 接口,需要手动转换。

还有 iterator 或 span 有时会遇到。例如写 hash_map find,会有返回 iterator 和 const_iterator 两个版本,const 版本可以直接 const_iterator{const_cast<T*>(this)->find(key)}

2. ({ expr; }) 是什么语法

GCC 扩展,https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

3. vcpkg 怎么给依赖打 patch

https://learn.microsoft.com/en-us/vcpkg/examples/patching