Skip to content

败犬日报 2025-03-17

1. 如何用可变参数给数组赋值

构造函数比较简单。赋值麻烦一点,要用 integer_sequence。

cpp
#include <cstdlib>
#include <utility>

template <size_t N>
struct Array {
    int array[N];

    template <typename... Ts>
    Array(Ts... args) : array{std::move(args)...} {}

    template <typename... Ts>
    void assign(Ts... args) {
        [&]<size_t... Is>(std::index_sequence<Is...>) {
            (..., (array[Is] = std::move(args)));
        }(std::index_sequence_for<Ts...>{});
    }
};

2. 引用的非空 hint

引用不能为空,编译器会根据这点对代码进行优化。

https://zhuanlan.zhihu.com/p/665536071 这个就讲了成员函数的 this 如果是 nullptr 会出问题的例子(即使成员函数没有使用 this)。

类似的还有 memcpy 也会有非空的假设 https://zhuanlan.zhihu.com/p/699259091

3. 在 ~/.bashrc 里写 exit 导致 ssh 登不上

记录一下离谱问题。

解决办法是 --norc,或者 scp 传过去一个 .bashrc 把原来的给覆盖了。

4. 几个计算机安全方面的事件

供应链攻击 https://www.bilibili.com/video/BV1tJ4m1L7Z3/;动态链接机制 https://insights.sei.cmu.edu/blog/carpet-bombing-and-directory-poisoning/