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 {
62
62
}
63
63
};
64
64
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 (); }
81
68
};
82
69
83
70
int main (int , char **) {
84
71
types::for_each (types::floating_point_types (), TestFloat ());
85
72
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
+ }
89
80
90
81
return 0 ;
91
82
}
Original file line number Diff line number Diff line change @@ -62,30 +62,21 @@ struct TestInt {
62
62
}
63
63
};
64
64
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 (); }
81
68
};
82
69
83
70
int main (int , char **) {
84
71
types::for_each (types::floating_point_types (), TestFloat ());
85
72
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
+ }
89
80
90
81
return 0 ;
91
82
}
You can’t perform that action at this time.
0 commit comments