Reputation: 1526
I have following code
#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;
}
I essentially want to ensure that the template argument have certain types, integral or floating point. There are two issues:
value_type
. I also want the class to work out if somebody is passing a raw pointer to an integral type or floating point. Is there an easy way to incorporate that?value_type
Upvotes: 0
Views: 497
Reputation: 4449
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
Upvotes: 2