File tree Expand file tree Collapse file tree 2 files changed +20
-38
lines changed
libcxx/test/std/numerics/c.math Expand file tree Collapse file tree 2 files changed +20
-38
lines changed Original file line number Diff line number Diff line change @@ -62,30 +62,21 @@ struct TestInt {
6262 }
6363};
6464
65- struct ConvertibleFloat {
66- int value;
67- ConvertibleFloat (int v) : value(v) {}
68- operator float () const { return static_cast <float >(value); }
69- };
70-
71- struct ConvertibleDouble {
72- int value;
73- ConvertibleDouble (int v) : value(v) {}
74- operator double () const { return static_cast <double >(value); }
75- };
76-
77- struct ConvertibleLongDouble {
78- int value;
79- ConvertibleLongDouble (int v) : value(v) {}
80- operator long double () const { return static_cast <long double >(value); }
65+ template <typename T>
66+ struct ConvertibleTo {
67+ operator T () const { return T (); }
8168};
8269
8370int main (int , char **) {
8471 types::for_each (types::floating_point_types (), TestFloat ());
8572 types::for_each (types::integral_types (), TestInt ());
86- assert (!std::isinf (ConvertibleFloat (0 )));
87- assert (!std::isinf (ConvertibleDouble (0 )));
88- assert (!std::isinf (ConvertibleLongDouble (0 )));
73+
74+ // Make sure we can call `std::isinf` with convertible types
75+ {
76+ assert (!std::isinf (ConvertibleTo<float >()));
77+ assert (!std::isinf (ConvertibleTo<double >()));
78+ assert (!std::isinf (ConvertibleTo<long double >()));
79+ }
8980
9081 return 0 ;
9182}
Original file line number Diff line number Diff line change @@ -62,30 +62,21 @@ struct TestInt {
6262 }
6363};
6464
65- struct ConvertibleFloat {
66- int value;
67- ConvertibleFloat (int v) : value(v) {}
68- operator float () const { return static_cast <float >(value); }
69- };
70-
71- struct ConvertibleDouble {
72- int value;
73- ConvertibleDouble (int v) : value(v) {}
74- operator double () const { return static_cast <double >(value); }
75- };
76-
77- struct ConvertibleLongDouble {
78- int value;
79- ConvertibleLongDouble (int v) : value(v) {}
80- operator long double () const { return static_cast <long double >(value); }
65+ template <typename T>
66+ struct ConvertibleTo {
67+ operator T () const { return T (); }
8168};
8269
8370int main (int , char **) {
8471 types::for_each (types::floating_point_types (), TestFloat ());
8572 types::for_each (types::integral_types (), TestInt ());
86- assert (!std::isnan (ConvertibleFloat (0 )));
87- assert (!std::isnan (ConvertibleDouble (0 )));
88- assert (!std::isnan (ConvertibleLongDouble (0 )));
73+
74+ // Make sure we can call `std::isnan` with convertible types
75+ {
76+ assert (!std::isnan (ConvertibleTo<float >()));
77+ assert (!std::isnan (ConvertibleTo<double >()));
78+ assert (!std::isnan (ConvertibleTo<long double >()));
79+ }
8980
9081 return 0 ;
9182}
You can’t perform that action at this time.
0 commit comments