V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
wutiantong
V2EX  ›  问与答

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

  •  
  •   wutiantong · Sep 6, 2019 · 1166 views
    This topic created in 2426 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   ·   5358 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:49 · PVG 11:49 · LAX 20:49 · JFK 23:49
    ♥ Do have faith in what you're doing.