Skip to content

Commit

Permalink
Extract template and leave comment
Browse files Browse the repository at this point in the history
  • Loading branch information
robincaloudis committed Jul 16, 2024
1 parent c858bb6 commit 2e6a04d
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions libcxx/test/std/numerics/c.math/isfinite.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,21 @@ struct TestInt {
}
};

struct ConvertibleFloat {
int value;
ConvertibleFloat(int v) : value(v) {}
operator float() const { return static_cast<float>(value); }
};

struct ConvertibleDouble {
int value;
ConvertibleDouble(int v) : value(v) {}
operator double() const { return static_cast<double>(value); }
};

struct ConvertibleLongDouble {
int value;
ConvertibleLongDouble(int v) : value(v) {}
operator long double() const { return static_cast<long double>(value); }
template <typename T>
struct ConvertibleTo {
operator T() const { return {}; }
};

int main(int, char**) {
types::for_each(types::floating_point_types(), TestFloat());
types::for_each(types::integral_types(), TestInt());
assert(std::isfinite(ConvertibleFloat(0)));
assert(std::isfinite(ConvertibleDouble(0)));
assert(std::isfinite(ConvertibleLongDouble(0)));

// Make sure we can call `std::isfinite` with convertible types
{
assert(std::isfinite(ConvertibleTo<float>()));
assert(std::isfinite(ConvertibleTo<double>()));
assert(std::isfinite(ConvertibleTo<long double>()));
}

return 0;
}

0 comments on commit 2e6a04d

Please sign in to comment.