boostorg / boostorg/core

boost::span cannot be constructed with iterators

Open
#119 21 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
156
Forks
116
PR merge metrics
No merged PRs in 30d

Description

`std::span` constructors 2 and 3 of [cppreference.com documentation](https://en.cppreference.com/w/cpp/container/span/span) support generic iterators, while `boost::span` accepts only pointers. A possible workaround is to apply the operators `&*` to the iterators.

https://godbolt.org/z/sjEozr6M5

```c++
#include
#include

#include

void foo(const std::vector& v) {
const auto std_span = std::span(v.begin(), v.end()); // fine
// const auto boost_span = boost::span(v.begin(), v.end()); // broken
const auto boost_span = boost::span(&*v.begin(), &*v.end()); // fine with hack
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.