boostorg / boostorg/histogram

indexed(histogram) not usable with ranges

Open
#355 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
334
Forks
76
PR merge metrics
No merged PRs in 30d

Description

While a `boost::histogram` can be used as a range in C++20, an `indexed(histogram)` cannot. At least for me (tested with clang++ 13 and g++ 11.3), the following code does not compile:

```c++
#include
#include
#include

#include

int main() {
using namespace boost::histogram;

std::mt19937 rng;
std::exponential_distribution dist;

auto hist = make_histogram(axis::regular<>(20, 1, 10.0));

for (int i = 0; i < 1'000; ++i) {
hist(dist(rng));
}

// these work
auto r1 = std::ranges::subrange(hist.cbegin(), hist.cend());
auto v1 = hist | std::views::transform([] (auto&& x) {return 1;});

// these don't:
auto x = indexed(hist);
auto r2 = std::ranges::subrange(x.cbegin(), x.cend());
auto v2 = indexed(hist) | std::views::transform([] (auto&& x) {return 1;});

return 0;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.