Bul*_*net 2 c++ template-argument-deduction
meow()这里第二次调用怎么编译呢?
#include <iostream>
struct F {
struct E {
using is_it_safe = bool;
};
E e;
};
template<typename T, typename = typename T::E::is_it_safe>
const void* meow(T const& t)
{
return &t;
}
int main() {
F f;
meow(f); // meow<F, bool>
meow(f.e); // meow<F::E, bool> ??
}
Run Code Online (Sandbox Code Playgroud)
F::E没有嵌套E,那么编译器如何推导第二个模板参数?
E有一个注入类名,所以它E::E就是它本身(E)。
F::E::E::is_it_safe也是如此bool,因为类F::E::E是E:
F::E::E::is_it_safe x;
static_assert(std::is_same_v<decltype(x), bool>);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |