Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-4105: [C++] Remove boost::lexical_cast and boost::math #3277

Merged
merged 6 commits into from
Jan 4, 2025

Conversation

wgtmac
Copy link
Member

@wgtmac wgtmac commented Dec 31, 2024

What is the purpose of the change

Remove boost::lexical_cast and boost::math

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

Documentation

  • Does this pull request introduce a new feature? no

@github-actions github-actions bot added the C++ Pull Requests for C++ binding label Dec 31, 2024
Comment on lines 414 to 416
std::ostringstream oss;
if (boost::math::isfinite(t)) {
oss << boost::lexical_cast<std::string>(t);
} else if (boost::math::isnan(t)) {
if (std::isfinite(t)) {
oss << t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does std::locale::global affect the double-to-string formatting here; for example, can it output "12,34" with a comma, which would be invalid in JSON?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. Perhaps using std::to_chars is better?

Copy link
Member Author

@wgtmac wgtmac Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the std::to_chars functions that take an std::chars_format parameter are available in GCC 11 (changes) but the ARM CI has 9.4.0.

oss.imbue(std::locale::classic()) then? Does Avro have tests in which the C++ global locale is not classic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick check and it seems there isn't any test case like that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears the lexical_cast also has the same locale based behavior. Given that there is no clean solution for C++14, and to_string is no worse than lexical_cast should we proceed with this PR? I'll merge this PR if no objection is forthcoming for a day or two.

sep2();
}

void encodeNumber(float t) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a specialization, it'll better to be explicit about it. Please add: template <> before this line.

@@ -404,9 +404,25 @@ public:

template<typename T>
void encodeNumber(T t) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a template function encodeNumber and its specializations, it'll be cleaner to have (a) a template function numberToString and its specialization to convert the given number into a string and then (b) have a single function encodeNumber that puts the string into out_.

@@ -415,9 +431,10 @@ public:
void encodeNumber(double t) {
Copy link
Contributor

@thiru-mg thiru-mg Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a single specialization for float and double:

template<typename T>
typename std::enable_if<std::is_floating_point<T>::value, void>::type
encodeNumber(T t) {
    // implementation common to float/double
}

template<typename T>
typename std::enable_if<!std::is_floating_point<T>::value, void>::type
encodeNumber(T t) {
    // implementation for all other types
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please take a look again. Thanks!

@wgtmac wgtmac force-pushed the remove_boost_math branch from e7fe237 to 4c5a9ba Compare January 1, 2025 12:51
@thiru-mg thiru-mg merged commit debc682 into apache:main Jan 4, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Pull Requests for C++ binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants