C++被认为是静态类型的。我明白那个。模板:静态类型还是动态?
我不明白这是如何适用于模板。
这里是不能在编译时确定一个类型的一个简单的例子:
template <typename... t>
struct foo {
using type = typename foo<t..., t...>::type;
};
foo<int>::type x; // type of x cannot be determined without running meta-program
我相信存在这样的情况是不可能的检测类型错误不解决停机问题。
所以我的问题是,为什么不考虑动态类型的模板?
有没有元程序运行,只是一些类型实例,所有发生在C++程序的**编译时**。 – Xeo 2012-01-02 03:01:59
@Xeo它不能实例化任何东西,因为它不能确定类型 – Pubby 2012-01-02 03:03:49
我假设编译器仍然会在编译时间中试图找出这种类型。任何证明违背这一假设? – 2012-01-02 03:04:20