V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wutiantong
V2EX  ›  问与答

[C++17] 请教各位大佬,如何构造一个完全值语义的二叉树类型?

  •  
  •   wutiantong · 2019-09-06 14:09:13 +08:00 · 820 次点击
    这是一个创建于 1692 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想要的是类似这样的东西:

    struct leaf_type {};
    struct value_type {};

    struct binary_tree
    {
    value_type val;
    std::variant<binary_tree, leaf_type> left_branch;
    std::variant<binary_tree, leaf_type> right_branch;
    };

    但 std::variant 其实不支持这种写法,
    请问各位大佬这方面有什么最佳实践么?
    3 条回复    2019-09-06 15:35:39 +08:00
    wutiantong
        1
    wutiantong  
    OP
       2019-09-06 15:15:27 +08:00
    还是自己造轮子得了
    geelaw
        2
    geelaw  
       2019-09-06 15:17:52 +08:00
    自己处理复制就行了。
    wutiantong
        3
    wutiantong  
    OP
       2019-09-06 15:35:39 +08:00
    @geelaw 自己处理复制太麻烦了,我还是打算抽象一些封装基于 STL 容器上做
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5923 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:56 · PVG 09:56 · LAX 18:56 · JFK 21:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.