我有以下这个问题中的错误消息,类别的类模板指南基于基于参数。
<source>:44:8: error: template parameters not deducible in partial specialization:
44 | struct A3<int> : A<N> {
| ^~~~~~~
<source>:44:8: note: 'N'
Compiler returned: 1
如何查看 a3
和 a
的扣除指南?
编辑:删除了无效的摘录。好吧,评论讨论变得非常糟糕。 用于生成隐式推力指南的规则 可能很复杂,尤其是聚集的。我认为能够看到自动生成的任何指南将是有用的,尤其是如果您不熟悉C ++并想调整隐式指南。这就是为什么这个问题很重要的原因,即使摘录无效。
I have the following error message from this question, class template deducation guide for struct-based parameters.
<source>:44:8: error: template parameters not deducible in partial specialization:
44 | struct A3<int> : A<N> {
| ^~~~~~~
<source>:44:8: note: 'N'
Compiler returned: 1
How can I view the deduction guides for A3
and A
?
Edit: removed invalid excerpt. Well, the comment discussion got horribly sidetracked. The rules for generating implicit deduction guides can be complicated, especially for aggregates. I think it would be useful to be able to see any guides which have been automatically generated, especially if you are new to C++ and want to tweak the implicit guides. That's why this question is important even if the excerpt was invalid.
发布评论
评论(1)
您可以从Clang生成AST树。它显示了诸如隐式声明为特殊方法(默认构造函数等)以及隐式扣除指南之类的事物。然而,扣除指南似乎只有在实际被用来推断模板时才显示。我不熟悉该工具,无法告诉您是否有办法向它们展示。
例如,对于此代码:
这是相关输出:
您可以看到a&gt;
auto(t) - &gt; a&lt; t&gt;
的“隐式&lt;扣除指南”。玩它”或或 generate it it 自己。
另一个工具是 cppinsight (也是由clang构建的)。它仅显示扣除指南的“专业化”:
You can generate the AST tree from clang. It shows a bunch on things like implicitly declared special methods (default constructors etc.) as well as implicit deduction guides. The deduction guides however seem to be shown only when they are actually used to deduce a template. I am not familiar with the tool and couldn't tell you if there is a way to show them regardless.
E.g. for this code:
This is the relevant output:
You can see "implicit <deduction guide for A >
auto (T) -> A<T>
".Play with it on godbolt or generate it yourself.
Another tool is cppinsight (which is built from clang also). It only shows the "specialization" of the deduction guide if it's used: