{ return _Iterator<false>(ranges::begin(_M_base)); }
constexpr auto
- begin() const requires __detail::__simple_view<_Vp>
+ begin() const requires range<const _Vp>
{ return _Iterator<true>(ranges::begin(_M_base)); }
constexpr auto
- end()
+ end() requires (!__detail::__simple_view<_Vp> && !common_range<_Vp>)
{ return _Sentinel<false>{ranges::end(_M_base)}; }
constexpr auto
- end() requires common_range<_Vp>
+ end() requires (!__detail::__simple_view<_Vp> && common_range<_Vp>)
{ return _Iterator<false>{ranges::end(_M_base)}; }
constexpr auto
base() const
{ return _M_end; }
- friend constexpr bool
- operator==(const _Iterator<_Const>& __x, const _Sentinel& __y)
- { return __y._M_equal(__x); }
-
- friend constexpr range_difference_t<_Base>
- operator-(const _Iterator<_Const>& __x, const _Sentinel& __y)
- requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
- { return __x._M_current - __y._M_end; }
-
- friend constexpr range_difference_t<_Base>
- operator-(const _Sentinel& __x, const _Iterator<_Const>& __y)
- requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>
- { return __x._M_end - __y._M_current; }
+ template<bool _Const2>
+ requires sentinel_for<sentinel_t<_Base>,
+ iterator_t<__detail::__maybe_const_t<_Const2, _Vp>>>
+ friend constexpr bool
+ operator==(const _Iterator<_Const2>& __x, const _Sentinel& __y)
+ { return __y._M_equal(__x); }
+
+ template<bool _Const2,
+ typename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
+ requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+ friend constexpr range_difference_t<_Base2>
+ operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
+ { return __x._M_current - __y._M_end; }
+
+ template<bool _Const2,
+ typename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
+ requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base2>>
+ friend constexpr range_difference_t<_Base>
+ operator-(const _Sentinel& __x, const _Iterator<_Const2>& __y)
+ { return __x._M_end - __y._M_current; }
friend _Sentinel<!_Const>;
};
VERIFY( ranges::equal(v1, x | views::values) );
}
+struct S
+{
+ friend bool
+ operator==(std::input_iterator auto const& i, S)
+ { return std::get<1>(*i) == 0; }
+};
+
+void
+test02()
+{
+ // This verifies that P1994R1 (and LWG3406) is implemented.
+ std::pair<std::pair<char, int>, long> x[]
+ = {{{1,2},3l}, {{1,0},2l}, {{1,2},0l}};
+ ranges::subrange r{ranges::begin(x), S{}};
+
+ auto v = r | views::keys;
+ VERIFY( ranges::equal(v, (std::pair<char, int>[]){{1,2},{1,0}}) );
+ ranges::subrange v2{ranges::begin(v), S{}};
+ VERIFY( ranges::equal(v2, (std::pair<char, int>[]){{1,2}}) );
+}
+
int
main()
{
test01();
+ test02();
}
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <ranges>
+
+namespace ranges = std::ranges;
+namespace views = std::views;
+
+void
+test01()
+{
+ std::tuple<int, int> x[] = {{0,0}};
+ auto v = x | views::elements<0>;
+ bool b = ranges::cbegin(v) == ranges::end(v);
+}
+
+void
+test02()
+{
+ std::tuple x = {0, 1};
+ auto v = views::single(x) | views::elements<0>;
+ auto i = ranges::cbegin(v);
+}