bluearc 最近的时间轴更新
bluearc

bluearc

V2EX 第 604582 号会员,加入于 2022-12-03 01:25:51 +08:00
bluearc 最近回复了
3 天前
回复了 StupidMan 创建的主题 生活方式 有丁克的嘛?现在感觉如何?
想清楚了那现在就慢慢过吧,但不要去结扎,给自己留个后路,不要把事情做绝
6 天前
回复了 CKAJ555 创建的主题 问与答 兄弟们 显卡要不要换啊 5090
没必要,就算是原价都感觉没必要,更何况现在黄牛张口就要 5w
收到,这就把椅子撤掉(
我也不希望看到 rust 进入主线内核,但这锅应该 Linus 来背,他的态度模糊导致了其他人的工作白费,虽然 Martin 试图借助媒体闹大给内核维护团队施压也不好;还有就是内核确实该考虑引入一些现代语言了,最起码该划一个 Cpp 的子集,一直坚持 C 那只能让内核维护团队的平均年龄越来越大
14 天前
回复了 haha2333haha 创建的主题 Apple 二手 m1 m2 主板当家用服务器
如果千八百能正常启动,那就无敌了,否则要 2000+那就没意思了
25 天前
回复了 NG6 创建的主题 macOS macOS 的 WindowServer 是真的没的救了吗?
这个问题似乎和特定应用有关,因为我是 3 周没关机占用 2.5g ,感觉也是泄露了但可以接受,不过外接屏幕 100%会快速泄露到不可接受的程度
31 天前
回复了 aqtata 创建的主题 C++ 这种情况如何消除几百个 if/else
@ysc3839 #56 我的,让 chatgpt 生成后感觉差不多就发了,上班摸鱼修改了下:
```
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>

class BaseClass {
public:
virtual ~BaseClass() = default;
virtual void print() = 0;
};

std::map<uint32_t, BaseClass *> reg;

template <std::uint32_t N> struct myclass : public BaseClass {
void print() override {
throw std::logic_error("Error: myclass<" + std::to_string(N) +
"> is not specialized.");
}
};

template <uint32_t N> void register_classes() {
reg[N] = new myclass<N>();
if constexpr (N > 0) {
register_classes<N - 1>();
}
}

template <> struct myclass<0x1ff> : public BaseClass {
void print() override { std::cout << "Specialized myclass<1f0>\n"; }
};
template <> struct myclass<0x1fa> : public BaseClass {
void print() override { std::cout << "Specialized myclass<2f0>\n"; }
};

// 通用模板函数
void foo(BaseClass *obj) {
obj->print(); // 调用特化模板的成员函数(如果有)
}

// 通用函数:根据运行时输入调用特定模板
void invoke_function(std::string_view hex_input) {
// 将字符串解析为 16 进制数值
std::uint32_t num;
std::stringstream ss;
ss << std::hex << hex_input;
ss >> num;
foo(reg[num]);
}

// 主程序
int main() {
register_classes<0xfff>();

try {
invoke_function("1ff");
invoke_function("1fa");
invoke_function("3f0");
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << '\n';
}
for (auto &pair : reg) {
delete pair.second;
}
return 0;
}
```

还是写特化模板就行,编译时给编译器传一个参数:-ftemplate-depth=4096 ;
32 天前
回复了 aqtata 创建的主题 C++ 这种情况如何消除几百个 if/else
用模板就可以解决,

```
#include <iostream>
#include <string>
#include <sstream>
#include <stdexcept>
#include <cstdint>


template<std::uint32_t N>
struct myclass {
void print() const {
throw std::logic_error("Error: myclass<" + std::to_string(N) + "> is not specialized.");
}
};

// 特化模板(如果需要为某些编号提供特定行为)
template<>
struct myclass<0x1f0> {
void print() const { std::cout << "Specialized myclass<1f0>\n"; }
};

template<>
struct myclass<0x2f0> {
void print() const { std::cout << "Specialized myclass<2f0>\n"; }
};

// 通用模板函数
template<std::uint32_t N>
void foo(myclass<N>& obj) {
std::cout << "Called foo<" << std::hex << N << ">\n";
obj.print(); // 调用特化模板的成员函数(如果有)
}

// 通用函数:根据运行时输入调用特定模板
void invoke_function(std::string_view hex_input) {
// 将字符串解析为 16 进制数值
std::uint32_t num;
std::stringstream ss;
ss << std::hex << hex_input;
ss >> num;
myclass<num> obj;
foo(obj);

}

// 主程序
int main() {
try {
invoke_function("1f0"); // 调用 foo<1f0>
invoke_function("2f0"); // 调用 foo<2f0>
invoke_function("3f0"); // 抛出异常
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << '\n';
}
return 0;
}

```

以后要添加新的,直接写个对应的特化模板就完事
sg 应该是有针对贫困学生的资助政策,奖学金什么的,可以先贷一年的费用,再确定第二年的费用,尽量减少贷款数额吧,虽然风险比较大,但我觉得是值得去的
40 天前
回复了 Bananana 创建的主题 Apple 各位双持的老哥是怎么携带两台手机的?
我是两个安卓,出门只带常用的小米 15 ,另一个一般就在家里用用
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1017 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 60ms · UTC 20:00 · PVG 04:00 · LAX 12:00 · JFK 15:00
Developed with CodeLauncher
♥ Do have faith in what you're doing.