8
考虑这样一个例子:能够保证所有的模板,模板参数调用用户提供扣除引导
#include <type_traits>
#include <string>
template <template <class> class TT> //#1
struct Foo {
static void foo() {
static_assert(std::is_same_v<decltype(TT("abc")), TT<std::string>>);
}
};
template <class T>
struct Bar {
Bar(T) {}
};
template <class T>
Bar(T) -> Bar<std::string>; //#2
int main() {
Foo<Bar>::foo();
}
[clang]以及[gcc]似乎都使用用户提供的扣除指南(#2)推导模板的模板参数时模板参数(#1)。它是符合标准的功能吗?
我真的期待这个答案,但是如果碰巧是错误的,那么我会把它拿回来;) –
作为一个小问题:你认为自动演绎指南不应该被应用吗? –
@ W.F。好吧,我彻底翻转了答案:) – Barry