wutiantong
V2EX  ›  问与答

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

  •  
  •   wutiantong · Sep 6, 2019 · 1232 views
    This topic created in 2453 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
        1
    wutiantong  
    OP
       Sep 6, 2019
    还是自己造轮子得了
    geelaw
        2
    geelaw  
       Sep 6, 2019
    自己处理复制就行了。
    wutiantong
        3
    wutiantong  
    OP
       Sep 6, 2019
    @geelaw 自己处理复制太麻烦了,我还是打算抽象一些封装基于 STL 容器上做
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3511 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 11:15 · PVG 19:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.