Skip to content

败犬日报 2024-11-16

1. shared_ptr 基类不需要虚析构也能正确析构

因为 shared_ptr 会保存一份具体类型的析构函数。

代码如下:

cpp
#include <cstdio>
#include <memory>
struct A {
    ~A() { printf("~A()\n"); }
};
struct B : A {
    ~B() { printf("~B()\n"); }
};
int main() {
    std::shared_ptr<A> b(new B);
    return 0;
}

输出

text
~B()
~A()

2. 有没有办法让 Qt::uniqueConnection 对 lambda 有效

https://stackoverflow.com/questions/56795629/testing-lambda-unique-connection-in-qt

Qt::uniqueConnection 不适用于 lambda

3. proxy 性能比不过 variant

功能不同,不能这么比。

能提前确定可能的类型的话肯定是 variant 拿到的类型信息多;proxy 类型擦除跟 function、function_ref 类似。