+2020-01-15 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/93267
+ * include/bits/iterator_concepts.h (__max_diff_type, __max_size_type):
+ Move here from <bits/range_access.h> and define using __int128 when
+ available.
+ (__is_integer_like, __is_signed_integer_like): Move here from
+ <bits/range_access.h>.
+ (weakly_incrementable): Use __is_signed_integer_like.
+ * include/bits/range_access.h (__max_diff_type, __max_size_type)
+ (__is_integer_like, __is_signed_integer_like): Move to
+ <bits/iterator_concepts.h>.
+ (__make_unsigned_like_t): Move here from <ranges>.
+ * include/std/ranges (__make_unsigned_like_t): Move to
+ <bits/range_access.h>.
+ (iota_view): Replace using-directive with using-declarations.
+ * testsuite/std/ranges/iota/93267.cc: New test.
+ * testsuite/std/ranges/iota_view.cc: Move to new 'iota' sub-directory.
+
2020-01-13 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/93244
= std::forward<_Tp>(__t);
};
+ namespace ranges::__detail
+ {
+#if __SIZEOF_INT128__
+ using __max_diff_type = __int128;
+ using __max_size_type = unsigned __int128;
+#else
+ using __max_diff_type = long long;
+ using __max_size_type = unsigned long long;
+#endif
+
+ template<typename _Tp>
+ concept __is_integer_like = integral<_Tp>
+ || same_as<_Tp, __max_diff_type> || same_as<_Tp, __max_size_type>;
+
+ template<typename _Tp>
+ concept __is_signed_integer_like = signed_integral<_Tp>
+ || same_as<_Tp, __max_diff_type>;
+
+ } // namespace ranges::__detail
+
+ namespace __detail { using ranges::__detail::__is_signed_integer_like; }
+
/// Requirements on types that can be incremented with ++.
template<typename _Iter>
concept weakly_incrementable = default_initializable<_Iter>
&& requires(_Iter __i)
{
typename iter_difference_t<_Iter>;
- requires signed_integral<iter_difference_t<_Iter>>;
+ requires __detail::__is_signed_integer_like<iter_difference_t<_Iter>>;
{ ++__i } -> same_as<_Iter&>;
__i++;
};
namespace __detail
{
- using __max_diff_type = long long;
- using __max_size_type = unsigned long long;
-
- template<typename _Tp>
- concept __is_integer_like = integral<_Tp>
- || same_as<_Tp, __max_diff_type> || same_as<_Tp, __max_size_type>;
-
- template<typename _Tp>
- concept __is_signed_integer_like = signed_integral<_Tp>
- || same_as<_Tp, __max_diff_type>;
-
template<integral _Tp>
constexpr make_unsigned_t<_Tp>
__to_unsigned_like(_Tp __t) noexcept
{ return __t; }
+ template<typename _Tp, bool _MaxDiff = same_as<_Tp, __max_diff_type>>
+ using __make_unsigned_like_t
+ = conditional_t<_MaxDiff, __max_size_type, make_unsigned_t<_Tp>>;
+
// Part of the constraints of ranges::safe_range
template<typename _Tp>
concept __maybe_safe_range
= !range<_Tp> && __pair_like<_Tp>
&& sentinel_for<tuple_element_t<1, _Tp>, tuple_element_t<0, _Tp>>;
- template<typename _Tp, bool _MaxDiff = same_as<_Tp, __max_diff_type>>
- using __make_unsigned_like_t
- = conditional_t<_MaxDiff, __max_size_type, make_unsigned_t<_Tp>>;
-
} // namespace __detail
enum class subrange_kind : bool { unsized, sized };
constexpr _Iterator&
operator+=(difference_type __n) requires __detail::__advanceable<_Winc>
{
- using namespace __detail;
+ using __detail::__is_integer_like;
+ using __detail::__is_signed_integer_like;
if constexpr (__is_integer_like<_Winc>
&& !__is_signed_integer_like<_Winc>)
{
constexpr _Iterator&
operator-=(difference_type __n) requires __detail::__advanceable<_Winc>
{
- using namespace __detail;
+ using __detail::__is_integer_like;
+ using __detail::__is_signed_integer_like;
if constexpr (__is_integer_like<_Winc>
&& !__is_signed_integer_like<_Winc>)
{
operator-(const _Iterator& __x, const _Iterator& __y)
requires __detail::__advanceable<_Winc>
{
- using namespace __detail;
+ using __detail::__is_integer_like;
+ using __detail::__is_signed_integer_like;
using _Dt = difference_type;
if constexpr (__is_integer_like<_Winc>)
{
|| (integral<_Winc> && integral<_Bound>)
|| sized_sentinel_for<_Bound, _Winc>
{
- using namespace __detail;
+ using __detail::__is_integer_like;
+ using __detail::__to_unsigned_like;
if constexpr (__is_integer_like<_Winc> && __is_integer_like<_Bound>)
return (_M_value < 0)
? ((_M_bound < 0)
--- /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=c++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <ranges>
+
+void
+test01()
+{
+ // PR libstdc++/93267
+ std::ranges::iota_view<long long, int> i(0, 3);
+ static_assert( std::weakly_incrementable<decltype(i.begin())> );
+ (void) std::ranges::begin(i);
+}
--- /dev/null
+// Copyright (C) 2019-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 run { target c++2a } }
+
+#include <ranges>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ int vals[5] = { };
+ int* out = vals;
+ for (int i : std::ranges::iota_view{1, 4})
+ *out++ = i;
+ VERIFY(out == vals + 3);
+ VERIFY(vals[0] == 1);
+ VERIFY(vals[1] == 2);
+ VERIFY(vals[2] == 3);
+ VERIFY(vals[3] == 0);
+}
+
+void
+test02()
+{
+ auto v = std::ranges::views::iota(4);
+ auto it = v.begin();
+ VERIFY( *it == 4 );
+ ++it;
+ VERIFY( *it == 5 );
+ it++;
+ VERIFY( *it == 6 );
+}
+
+void
+test03()
+{
+ auto v = std::ranges::views::iota(10, 15);
+ auto it = v.begin();
+ VERIFY( *it == 10 );
+ it += 2;
+ VERIFY( *it == 12 );
+ it += 2;
+ VERIFY( *it == 14 );
+ ++it;
+ VERIFY( it == v.end() );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+}
+++ /dev/null
-// Copyright (C) 2019-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 run { target c++2a } }
-
-#include <ranges>
-#include <testsuite_hooks.h>
-
-void
-test01()
-{
- int vals[5] = { };
- int* out = vals;
- for (int i : std::ranges::iota_view{1, 4})
- *out++ = i;
- VERIFY(out == vals + 3);
- VERIFY(vals[0] == 1);
- VERIFY(vals[1] == 2);
- VERIFY(vals[2] == 3);
- VERIFY(vals[3] == 0);
-}
-
-void
-test02()
-{
- auto v = std::ranges::views::iota(4);
- auto it = v.begin();
- VERIFY( *it == 4 );
- ++it;
- VERIFY( *it == 5 );
- it++;
- VERIFY( *it == 6 );
-}
-
-void
-test03()
-{
- auto v = std::ranges::views::iota(10, 15);
- auto it = v.begin();
- VERIFY( *it == 10 );
- it += 2;
- VERIFY( *it == 12 );
- it += 2;
- VERIFY( *it == 14 );
- ++it;
- VERIFY( it == v.end() );
-}
-
-int
-main()
-{
- test01();
- test02();
- test03();
-}