V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  nnnnnnamgn  ›  全部回复第 11 页 / 共 17 页
回复总数  324
1 ... 3  4  5  6  7  8  9  10  11  12 ... 17  
2025 年 3 月 18 日
回复了 pamphrey 创建的主题 职场话题 求指点迷津:老家年到手十万公务员 vs 大厂年包 30w
上海 30w ,那综合生活成本下来真不如老家公务员,而且还是省会又离家近,如果是县城乡镇公务员那才得考虑考虑
2025 年 3 月 9 日
回复了 biochen 创建的主题 程序员 Manus 是小甜甜还是牛夫人?
营销大王罢
手机连 wifi 正常吗?还是说用流量才正常?按理说同一片区域的同一运营商 dns 都是相同的
2025 年 3 月 8 日
回复了 zhoudaiyu 创建的主题 硬件 海光 cpu 性能问题疑问
去找找哪个云提供海光的实例,部署上测试看看
2025 年 3 月 6 日
回复了 zhangkai1024 创建的主题 生活 高中取消早晚自习老师激动得睡不着
@whp1473 #39 其实就是河南和河北卷,山东资源比其他三个好多了,山西那是招生名额少,教育资源也不好,躺平了
2025 年 3 月 2 日
回复了 yohane 创建的主题 Apple 心痒痒 m4 macmini,该不该冲动消费?
有闲钱就买,俺买来已经吃灰了(现在放在家里跑 orbstack,jellyfin,当 all in one 用
2025 年 2 月 20 日
回复了 Suger828 创建的主题 程序员 为什么都说是 go 替代了 PHP 而不是 Java , nextjs 这些
next.js 在国内流行吗?
2025 年 2 月 14 日
回复了 StupidMan 创建的主题 生活方式 有丁克的嘛?现在感觉如何?
想清楚了那现在就慢慢过吧,但不要去结扎,给自己留个后路,不要把事情做绝
2025 年 2 月 11 日
回复了 CKAJ555 创建的主题 问与答 兄弟们 显卡要不要换啊 5090
没必要,就算是原价都感觉没必要,更何况现在黄牛张口就要 5w
2025 年 2 月 11 日
回复了 vanpeisi7 创建的主题 职场话题 为什么一坐到工位上就感到疲惫、心慌?
收到,这就把椅子撤掉(
2025 年 2 月 8 日
回复了 wniming 创建的主题 Linux 如何看 Hector Martin 退出上游 Linux 内核开发这件事?
我也不希望看到 rust 进入主线内核,但这锅应该 Linus 来背,他的态度模糊导致了其他人的工作白费,虽然 Martin 试图借助媒体闹大给内核维护团队施压也不好;还有就是内核确实该考虑引入一些现代语言了,最起码该划一个 Cpp 的子集,一直坚持 C 那只能让内核维护团队的平均年龄越来越大
2025 年 2 月 3 日
回复了 haha2333haha 创建的主题 Apple 二手 m1 m2 主板当家用服务器
如果千八百能正常启动,那就无敌了,否则要 2000+那就没意思了
2025 年 1 月 23 日
回复了 NG6 创建的主题 macOS macOS 的 WindowServer 是真的没的救了吗?
这个问题似乎和特定应用有关,因为我是 3 周没关机占用 2.5g ,感觉也是泄露了但可以接受,不过外接屏幕 100%会快速泄露到不可接受的程度
2025 年 1 月 17 日
回复了 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 ;
2025 年 1 月 16 日
回复了 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;
}

```

以后要添加新的,直接写个对应的特化模板就完事
2025 年 1 月 9 日
回复了 IRuNamu 创建的主题 职场话题 Base 广州 15K 外包网易 or 新二自费两年硕?
sg 应该是有针对贫困学生的资助政策,奖学金什么的,可以先贷一年的费用,再确定第二年的费用,尽量减少贷款数额吧,虽然风险比较大,但我觉得是值得去的
2025 年 1 月 8 日
回复了 Bananana 创建的主题 Apple 各位双持的老哥是怎么携带两台手机的?
我是两个安卓,出门只带常用的小米 15 ,另一个一般就在家里用用
@xtx window server 似乎有轻微的内存泄露,根据自己的情况定时重启好一点
2025 年 1 月 6 日
回复了 zhwguest 创建的主题 支付宝 只愿意用微信支付的原因
@bluearc 不过我基本是哪个有优惠用哪个,之前支付宝推广碰一碰,在超市第一次用减了 10 块
1 ... 3  4  5  6  7  8  9  10  11  12 ... 17  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5926 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 145ms · UTC 02:45 · PVG 10:45 · LAX 19:45 · JFK 22:45
♥ Do have faith in what you're doing.