MoYi123 最近的时间轴更新
MoYi123

MoYi123

V2EX 第 469223 号会员,加入于 2020-02-14 14:02:50 +08:00
MoYi123 最近回复了
20 小时 1 分钟前
回复了 rednose1037 创建的主题 C++ mac clion 调试怎么才能看到 stl 容器的值
直接用 gdb terminal print 能打印出来吗? 先确定一下是 gdb 的问题还是 clion 的.

如果确定是 clion 的问题, 可以找 jetbrains 的人帮你,
我之前也遇到过 clion 里的 gdb 有错误, 但是 gdb print 是好的, 后来删了一个 tmp 下的缓存文件就好了.
https://youtrack.jetbrains.com/issue/CPP-41050/Debugging-with-GDB-in-remote-toolchains-is-broken-by-CLion-update
10 天前
回复了 Niner 创建的主题 Java update 大家会允许这样写吗?
没并发问题吧, 这里只是用了一个比较蠢的办法去构造了 User u 而已.
17 天前
回复了 aqtata 创建的主题 C++ 这种情况如何消除几百个 if/else
想要酷可以参考 std::visit 的做法. 编译期生成一个 Invoke_array, 下面的例子是从运行期的 int 转特定类型到 lambda 中的例子. 稍微改改就能用于你的需求.

using namespace std;

constexpr std::array cached_type_ints = {1};

struct void_ptr {
int type;
void *ptr;
};

template <int T> struct Int2Type;

template <> struct Int2Type<1> {
using type = int;
};

template <typename Func, typename> class Visitor;

template <typename Func, std::size_t... pos>
class Visitor<Func, std::index_sequence<pos...>> {
public:
using return_type =
std::invoke_result_t<Func, Int2Type<cached_type_ints[0]>::type *>;
using fn_type = return_type (*)(Func &&, void *);

template <int16_t type_int>
static auto func_wrapper(Func &&func, void *ptr) -> return_type {
using real_type = typename Int2Type<type_int>::type;
return func(static_cast<real_type *>(ptr));
}

static auto visit(Func &&func, const void_ptr &item) -> return_type {
constexpr static std::array<fn_type, cached_type_ints.size()> invoke_map = {
func_wrapper<cached_type_ints[pos]>...};

size_t idx = std::ranges::lower_bound(cached_type_ints.begin(),
cached_type_ints.end(), item.type) -
cached_type_ints.begin();
if (idx >= invoke_map.size() or cached_type_ints[idx] != item.type)
[[unlikely]] {
throw std::bad_variant_access();
}
return invoke_map[idx](std::forward<Func>(func), item.ptr);
}
};

template <typename Func> auto visit(Func &&func, const void_ptr &item) {
using visitor = Visitor<decltype(func),
std::make_index_sequence<cached_type_ints.size()>>;
return visitor::visit(std::forward<Func>(func), item);
}

inline auto usage() {
auto item = void_ptr{.ptr = new int(1), .type = 1};
visit(
[](auto *ptr) {
print(*ptr);
delete ptr;
},
item);
}
19 天前
回复了 cj323 创建的主题 程序员 函数式编程适不适合游戏开发
用 erlang/elixir 的很大一部分是做游戏后端的.
问数据库优化的问题不贴 explain 就算了, 现在连 sql 都没有了.
wd40 精密仪器版应该可以, 我手柄进饮料就是这么修好的.
33 天前
回复了 htxy1985 创建的主题 程序员 求一款比较成熟的 golang 服务端热更方案
有状态服务更新用 erlang 热更新都挺麻烦的, go 基本不可能了.
34 天前
回复了 iamtuzi3333 创建的主题 程序员 大佬们,请教一下数据读取
没必要, 数据库一般会用一些压缩算法, 肯定比你支持存 json 文件要省的.
数据库里用 partition table, 按日期分
内存溢出肯定是你代码有错, 86400*200 个 float 应该还不到 100MB.
个人经验, 工作中看到 “封装” 这个 2 个字就没好事.
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1943 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 11:11 · PVG 19:11 · LAX 03:11 · JFK 06:11
Developed with CodeLauncher
♥ Do have faith in what you're doing.