【发布时间】:2017-04-29 03:00:39
【问题描述】:
此代码用于在 Clang 3.8 中编译,在 VS 2017 中仍可编译,但在 Clang 3.9 中开始发出错误。
template <typename D, typename ... I>
struct impl : I ...
{};
template <typename D, typename ... I>
void f(impl<D, I...> const&)
{}
struct A : impl<A> {};
struct B : impl<B, A> {};
int main()
{
f(A());
f(B()); // Error
}
Clang 3.9 说
<source>:15:5: error: no matching function for call to 'f'
f(B());
^
<source>:6:6: note: candidate template ignored: failed template argument deduction
void f(impl<D, I...> const&)
^
所有三个编译器都在运行: https://godbolt.org/g/OKFpPl
我希望f(A()) 推断D = A, I... = <> 和f(B()) 推断D = B, I... = A,然后可以将其推断为impl 的一个实例。我的最终目标是检测impl 的参数包中的类型,它们本身就是impl 的实例。我是不是走错了路?
【问题讨论】:
-
我发现的最简单的解决方法:wandbox.org/permlink/DxJmdi4YV0F4mPT7
标签: c++ templates variadic-templates crtp template-argument-deduction