beman-project / optional26

Beman.Optional26: `std::optional` extensions targeting C++26
Apache License 2.0
14 stars 9 forks source link

contiguous_iterator should be constexpr #63

Closed qustrolabe closed 3 weeks ago

qustrolabe commented 1 month ago

std::views::join on beman::optional26::optional doesn't work in constexpr context in my code https://godbolt.org/z/Ed11G66s3 (switch preprocessor if 1 to see error)

This code doesn't work in constexpr:

auto range_result = view_of_optionals | std::views::join | std::views::take(100);

I expected it work like this C++23 code:

auto range_result = view_of_optionals
        | std::views::filter([](const optional26<int>& opt) { return opt.has_value(); })
        | std::views::transform([](const optional26<int>& opt) { return *opt; })
        | std::views::take(100);

Filtering out all nullopt from view

With std::views::join compiler gives error that contiguous_iterator is not constexpr, so I simply tried editing it's declaration - marking everything I could as constexpr and afterwards this code worked as expected. So solely based on this I think it should be constexpr.

steve-downey commented 1 month ago

Will also check if draft standard has the bug.

frederick-vs-ja commented 1 month ago

Will also check if draft standard has the bug.

[optional.iterators]/1 is already requiring the iterator types meeting the contexpr iterator requirements. Such requirements are correctly copied into [optionalref.iterators]/1 in P2988R7.

So we should just add lacked constexpr in the implementation...