Fix IndexTransformIter
to be compatible with C++23
#9155
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 iteratorIndexTransformIter
has avalue_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 usingremove_cvref_t
(but written in the older style to avoid depending on the C++20 convenience type trait), whilereference
is the type that's being returned by theFn
invocation.Note that the actual return types of
operator*
andoperator[]
are being preserved (they continue to return theresult_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.