[PATCH 1/2] libstdc++: Implement ranges::adjacent_view from P2321R2
Jonathan Wakely
jwakely@redhat.com
Wed Aug 31 10:26:37 GMT 2022
On Tue, 30 Aug 2022 at 18:14, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
> + constexpr
> + _Iterator(__as_sentinel, iterator_t<_Base> __first, iterator_t<_Base> __last)
> + {
> + if constexpr (!bidirectional_range<_Base>)
> + for (auto& __it : _M_current)
> + __it = __last;
> + else
> + for (ssize_t __i = _Nm-1; __i >= 0; --__i)
ssize_t is defined by POSIX in <sys/types.h> but isn't in ISO C or
C++. It looks like MinGW defines it to ... something ... sometimes,
but I don't think we can rely on it for non-POSIX targets.
> + template<size_t _Nm>
> + struct _Adjacent : __adaptor::_RangeAdaptorClosure
> + {
> + template<viewable_range _Range>
> + requires (_Nm == 0) || __detail::__can_adjacent_view<_Nm, _Range>
> + [[nodiscard]]
> + constexpr auto
> + operator()(_Range&& __r) const
Does this attribute actually work here?
I thought we needed to use `operator() [[nodiscard]]` for functions
with a requires-clause, because otherwise the attribute gives a parse
error. Maybe I've misremembered the problem, and it just doesn't give
a -Wunused-result warning. The decl above is setting off my spidey
sense for some reason though.
More information about the Libstdc++
mailing list