iterator_traits<vehicle_part_iterator<T>>
is missing reference
#58643
Labels
[C++]
Changes (can be) made in C++. Previously named `Code`
Good First Issue
This is a good first issue for a new contributor
(S2 - Confirmed)
Bug that's been confirmed to exist
Describe the bug
I work on MSVC's C++ Standard Library implementation, and we regularly build popular open-source projects, including yours, with our development toolsets in order to prevent regressions from breaking your code. This also allows us to provide advance notice of breaking changes - in this case, we've found an issue in your code that will cause compiler errors with an upcoming version of the Visual C++ toolset.
Specifically, we merged microsoft/STL#2447 implementing a new optimization in the
minmax_element
family of algorithms. This optimization involves inspecting iterator types to see if they're eligible for the optimization, and as part of that, we need to inspectiterator_traits<UserDefinedIterator>::reference
at compile-time.There's an
iterator_traits<vehicle_part_iterator<T>>
in your codebase that does not provide areference
typedef (orpointer
):Cataclysm-DDA/src/vpart_range.h
Lines 84 to 90 in bcd8b3b
When compiled with the upcoming VS 2022 17.4 Preview 1 toolset or later, this will emit an error of the form:
The fix should be straightforward (and backwards-compatible with all previous toolsets, and other compilers). According to the C++ Working Paper N4910 25.3.2.3 [iterator.traits]/1, the
reference
andpointer
typedefs should match whatoperator*()
andoperator->()
return, respectively:Cataclysm-DDA/src/vpart_range.h
Lines 53 to 57 in bcd8b3b
Therefore, this should be added to
iterator_traits<vehicle_part_iterator<T>>
:Unrelated aside: I saw the comment "This requires adding more operators to the iterator, which may not be efficient." It is certainly tedious to provide the large number of operators required for random-access iterators (including the obscure
n + iter
). However, this will have a minimal impact on compile-time throughput (build speed), and will typically improve run-time performance. This is because many STL algorithms and data structures will detect random-access iterators automatically, and perform constant-time operations. If they only have forward-iterator operations to work with, they have to fall back to linear-time operations. A simple example is calculating the distance between two iterators (which is used byvector
range construction and many other places).std::distance()
will detect random-access iterators and calllast - first
which performs a single subtraction, but for forward iterators it must repeatedly increment a copy offirst
until it's equal tolast
.Steps to reproduce
See bug description (requires VS 2022 17.4 Preview 1 or later to reproduce, which has not yet shipped).
Expected behavior
Cataclysm-DDA should compile without errors.
Screenshots
No response
Versions and configuration
Compile-time issue, not running the game. Again, requires VS 2022 17.4 Preview 1 (or the latest build of https://github.com/microsoft/STL ).
Additional context
No response
The text was updated successfully, but these errors were encountered: