如何在编译时(在实际编译和运行程序之前)其参数之一的值已知/未知的情况下专门化模板函数?
我还不知道怎么办。
idea 1:
#include <type_traits>
#include <iostream>
int main(void){
int a; //value of a is not known at compile time
bool b = (a == a); //value of b is known at compile time.
std::is_assignable< constexpr bool, bool >::value
}
//g++ magic.cpp -std=c++14
//error: wrong number of template arguments (1, should be 2)
// std::is_assignable< constexpr bool, bool >::value
Idea 2:
#include <type_traits>
#include <iostream>
int main(void){
const int a=1;
int b = (a == a);
std::cout << __builtin_constant_p (a) << std::endl;
std::cout << __builtin_constant_p (b) << std::endl;
}
//prints 0 and 0.
好吧,我猜你的意思是type的论点,对吗?值对于部分模板专业化并不重要......
然后:这不能完成。
模板的参数类型必须在编译时已知。编译器还应该如何生成正确的代码?
同样,对于部分模板特化,出于同样的原因,必须在编译时知道类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)