martinmoene / span-lite

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
497 stars 41 forks source link

Support for iterator constructors/deduction guides #61

Closed Ryan-rsm-McKenzie closed 3 years ago

Ryan-rsm-McKenzie commented 4 years ago

Is any support for this planned? See here and here for reference.

martinmoene commented 4 years ago

@Ryan-rsm-McKenzie Thanks for your question/suggestion. I wasn't aware yet of these deduction guides. I'll take a look, will not be immediately though.

martinmoene commented 4 years ago

span iterator deduction guide:

template<class It, class EndOrSize>
span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;

Constraints: It satisfies contiguous_­iterator. std::iter_reference_t (C++20, p1037) std::remove_reference_t (C++14/C++11)

Ryan-rsm-McKenzie commented 3 years ago

The new deduction guides are failing to deduce reference types for iterators, presumably because of this line: https://github.com/martinmoene/span-lite/blob/81f7b15ea0a806718bd2ac72db5f09915d7e4843/include/nonstd/span.hpp#L665

Here's a godbolt link.

martinmoene commented 3 years ago

Thanks @Ryan-rsm-McKenzie for your feedback. Currently my attention is a bit too scattered to do a good job in one go. A little back and forth may help :)

Having a look at it...

martinmoene commented 3 years ago

@Ryan-rsm-McKenzie I think this issue can be closed, otherwise please reopen it.

Ryan-rsm-McKenzie commented 3 years ago

You're missing an iterator based constructor, so code like this won't compile.

Ryan-rsm-McKenzie commented 3 years ago

I can't re-open the issue because you closed it

Ryan-rsm-McKenzie commented 3 years ago

this works

martinmoene commented 3 years ago

Thanks @Ryan-rsm-McKenzie !