败犬日报 2025-05-09
1. std::bind_front
相关的模板科技
cpp
struct Foo {
void A(int) {}
template <auto Foo::*func, typename... Args>
static void proxy(void* pvUser, Args... args) {
return (static_cast<Foo*>(pvUser)->*func)(args...);
};
};
int main() {
Foo foo;
auto f = Foo::proxy<&Foo::A>;
f(&foo, 42); // error: too few arguments to function
}
上面的代码 f 被推导成了普通的函数指针 void (*)(void*)
,所以无法传入 42 这个参数。要解决这个问题,可以把 proxy 改成泛型 lambda 模板:
cpp
struct Foo {
void A(int) {}
template <auto Foo::*func>
static constexpr auto proxy = [](void* pvUser, auto... args) {
return (static_cast<Foo*>(pvUser)->*func)(args...);
};
};
但是 C++11 没有泛型 lambda 怎么办?不能直接 auto 了,只能萃取出 Args...
的具体类型。
到了 C++26 就简单了,可以直接 std::bind_front
:
cpp
#include <functional>
struct Foo {
void A(int) {}
};
int main() {
Foo foo;
auto f = std::bind_front<&Foo::A>(); // 更新:原来的 auto f = std::bind_front(&Foo::A); 是 C++20 写法,可能有额外开销
f(&foo, 42);
}
2. static 模板函数明明用了却报 unused
答案是 caller 是个模板函数,没实例化不一定算用。
3. QQ 群机器人收集聊天记录可能有隐私问题,最好加群时需要同意隐私协议
败犬日报是纯人工记录的,不涉及。
4. github 上的项目可以用 deepwiki 做成知识库
例如群友的问题 duckdb的string类型是如何进行存储的?https://deepwiki.com/search/duckdbstring_06910986-84f7-450e-8e0f-b32284cc8373
5. deepwiki 用了 RAG 吗
应该是。