wutiantong
V2EX  ›  问与答

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

  •  
  •   wutiantong · Sep 6, 2019 · 1541 views
    This topic created in 2628 days ago, the information mentioned may be changed or developed.
    我想要的是类似这样的东西:

    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 replies  •  2019-09-06 15:35:39 +08:00
    wutiantong
    wutiantong
    OP
    Sep 6, 2019
    1
    还是自己造轮子得了
    geelaw
    geelaw
    Sep 6, 2019
    2
    自己处理复制就行了。
    wutiantong
    wutiantong
    OP
    Sep 6, 2019
    3
    @geelaw 自己处理复制太麻烦了,我还是打算抽象一些封装基于 STL 容器上做
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4338 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 08:59 · PVG 16:59 · LAX 00:59 · JFK 03:59
    ♥ Do have faith in what you're doing.