Fix span_iterator
unwrapping for MSVC
#1100
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.
@tiagomacarios encountered the following error:
Click to expand error context (which explains the proximate error, but in a verbose, complicated way):
The root cause is that GSL's
span_iterator
partially participates in MSVC's (unfortunately undocumented) iterator unwrapping machinery. Theranges
algorithms require more complicated unwrapping tech than the classic algorithms, sinceranges
algorithms can mix iterators with sentinels.The fix is to add a
_Prevent_inheriting_unwrap
typedef tospan_iterator
. As the name tersely indicates, this typedef allows the unwrapping machinery to have confidence that it's using unwrapping member functions that have been provided by the class itself and not any base class (because if this were inherited by aDerivedSpanIterator
, the typedef would still name the basespan_iterator
). This single typedef activates all of the necessaryranges
unwrapping machinery (a long, complicated tale) and allows the code to compile. With this fix:This is the exact same thing that STL iterators do, e.g. see https://github.com/microsoft/STL/blob/daa994bfc41c36196c536f2b68388f859d6bd656/stl/inc/vector#L211 for
std::_Vector_const_iterator
.