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

Fix IndexTransformIter to be compatible with C++23 #9155

Merged
merged 1 commit into from
May 12, 2023
Merged

Fix IndexTransformIter to be compatible with C++23 #9155

merged 1 commit into from
May 12, 2023

Conversation

StephanTLavavej
Copy link
Contributor

Fixes #9127.

In the STL's conventions, an iterator's value_type should always be "plain" - no cv-qualifiers and no references. Although this convention dates back to C++98, code could sometimes violate it and still compile, depending on the exact operations used by any instantiated templates. However, now that C++ has evolved to perform concept checking, stricter enforcement is happening within STL algorithms. XGBoost fails to compile with MSVC's /std:c++latest mode because its iterator IndexTransformIter has a value_type that doesn't follow the proper conventions.

This PR is my attempted fix, which appears to resolve the compilation issues, and "seems reasonable" to me - it changes the value_type to be plain by using remove_cvref_t (but written in the older style to avoid depending on the C++20 convenience type trait), while reference is the type that's being returned by the Fn invocation.

Note that the actual return types of operator* and operator[] are being preserved (they continue to return the result_of_t), it's just the mentioned typedef that's changing.

Because I work on the C++ Standard Library all day and haven't actually used XGBoost or run its tests, this PR could have subtle implications elsewhere. I hope that it's correct or at least a good start.

@hcho3 hcho3 requested a review from trivialfis May 11, 2023 23:40
Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

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

Thank you for the fix!

@trivialfis trivialfis merged commit 7375bd0 into dmlc:master May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants