败犬日报 2025-07-30
1. 为什么没有 is_specialization 的模板工具
提案 https://wg21.link/P2098R0 被搁置了,原因是不够通用,没法完美地处理类型参数 + 非类型参数的排列组合。
例如,找不到这么一个 is_specialization_of 的定义:
cpp
template <typename T, template </* 这里填啥能同时满足下面的要求 */> typename Template> is_specialization_of {};
using T1 = is_specialization_of<std::array<int, 1>, std::array>;
using T2 = is_specialization_of<std::vector<int>, std::vector>;
往期提到的 universal template 提案可以处理这个问题,但是也没过。
C++26 反射能解决,但是模板参数类型得是反射得到的类型(std::meta::info),不能直接填类型和模板。
2. catch 异常后能不能跳转回去
异常当然不行,可以用 algebraic effect。
或者传递的异常里有 continuation,但是不太符合异常的设计目的(不可恢复的错误)。
3. 大规模代码库怎么全局搜索
最好建索引再搜的方案,例如 https://oracle.github.io/opengrok/。
4. 位域的顺序是实现定义的吗
是的。https://zh.cppreference.com/w/cpp/language/bit_field.html#Notes