MoYi123 最近的时间轴更新
MoYi123

MoYi123

V2EX 第 469223 号会员,加入于 2020-02-14 14:02:50 +08:00
今日活跃度排名 1631
MoYi123 最近回复了
react 的是人写的.
go 的这个文档是通过代码里的注释直接生成的, 我从来不看这玩意.
只是高频更新不会导致死锁, 建议先把死锁的问题修好再看.
14 天前
回复了 rednose1037 创建的主题 C++ mac clion 调试怎么才能看到 stl 容器的值
lldb 和 gdb 和确定是不是 clion 的错误也没什么关系啊,
(lldb) print a
(std::unordered_map<int, std::vector<int> >) size=1 {
[0] = {
__cc_ = {
first = 1
second = size=3 {
[0] = 1
[1] = 2
[2] = 3
}
}
}
}

如果 lldb 能这样成功打印, 那肯定是 clion 的错误了, 直接找 jetbrains 就行了.
17 天前
回复了 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
27 天前
回复了 Niner 创建的主题 Java update 大家会允许这样写吗?
没并发问题吧, 这里只是用了一个比较蠢的办法去构造了 User u 而已.
34 天前
回复了 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);
}
36 天前
回复了 cj323 创建的主题 程序员 函数式编程适不适合游戏开发
用 erlang/elixir 的很大一部分是做游戏后端的.
问数据库优化的问题不贴 explain 就算了, 现在连 sql 都没有了.
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5504 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 06:58 · PVG 14:58 · LAX 22:58 · JFK 01:58
Developed with CodeLauncher
♥ Do have faith in what you're doing.