我有以下代码
#include <type_traits>
template<typename T, typename U, typename Tout>
requires std::is_integral< typename T::value_type >
&& std::is_floating_point< typename U::value_type >
&& std::is_floating_point< typename Tout::value_type >
class test
{
test() =default;
};
int main(int argc, char const *argv[])
{
/* code */
return 0;
}
我基本上想确保模板参数具有某些类型,整数或浮点数。有两个问题:
value_type
。如果有人将原始指针传递给整数类型或浮点数,我还希望该类能够计算出来。有没有一种简单的方法来合并它?value_type
template<typename T, typename U, typename Tout>
requires std::is_integral_v<typename T::value_type>
&& std::is_floating_point_v<typename U::value_type>
&& std::is_floating_point_v<typename Tout::value_type>
class test {
public:
test()=default;
};
int main() {
test<int, int, int> t;
}
main.cpp: In function 'int main()':
main.cpp:16:21: error: template constraint failure for 'template<class T, class U, class Tout> requires (is_integral_v<typename T::value_type>) && (is_floating_point_v<typename U::value_type>) && (is_floating_point_v<typename Tout::value_type>) class test'
16 | test<int, int, int> t;
| ^
main.cpp:16:21: note: constraints not satisfied
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句