在二叉树

时间:2018-01-31 15:37:20

标签: c++ binary-tree operator-keyword return-type auto

想象一下,您有一个简单的复合结构,如二叉树,并且您希望能够通过以下方式自动获取节点或叶子:

template <typename... Args>
auto operator()(Args...);

允许:

auto node_or_leaf = root()(1, 2, 3);

或者:

Node node = root()(1, 2);
Leaf leaf = root()(1, 2, 3);

我已经可以使用这种语法完成这项工作,但这不是返回类型推断。

template <typename T, typename... Args>
std::shared_ptr<T> operator()(Args...);

这需要一些模板专业化才能工作。我不确定这种语法是否适用于不同的编译器(适用于MSVC2017):

auto leaf = root->operator()<Leaf>(1, 2, 3);

我并没有真正对C ++ 14/17功能发出警告,所以如果你愿意,我需要你的帮助。我提前感谢你。

0 个答案:

没有答案
相关问题