Skip to content

Commit 24decb2

Browse files
committed
Extract template and leave comment
1 parent 18face0 commit 24decb2

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

libcxx/test/std/numerics/c.math/isinf.pass.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff 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

8370
int 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
}

libcxx/test/std/numerics/c.math/isnan.pass.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff 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

8370
int 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
}

0 commit comments

Comments
 (0)