aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-06-04 23:20:49 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-06-04 23:20:49 +0100
commitf2242ec0d3f1bb13c78ef3c21e0354d84fe57222 (patch)
tree1cda192a6b07a09edcc723f210b8a0f51483cb43
parentb825a22890740f341eae566af27e18e528cd29a7 (diff)
downloadgcc-f2242ec0d3f1bb13c78ef3c21e0354d84fe57222.zip
gcc-f2242ec0d3f1bb13c78ef3c21e0354d84fe57222.tar.gz
gcc-f2242ec0d3f1bb13c78ef3c21e0354d84fe57222.tar.bz2
libstdc++: Remove workarounds for constrained nested class templates
With PR c++/92078 and PR c++/92103 both fixed, nested class templates can now be constrained. That means a number of namespace-scope helpers can be moved to the class scope, so they're only visible where they're needed. * include/bits/iterator_concepts.h (__detail::__ptr, __detail::__ref) (__detail::__cat, __detail::__diff): Move to class scope in the relevant __iterator_traits specializations. (__iterator_traits<>): Use nested class templates instead of ones from namespace __detail. * include/bits/stl_iterator.h (__detail::__common_iter_ptr): Move to class scope in iterator_traits<common_iterator<I, S>>. (iterator_traits<common_iterator<I, S>>): Use nested class template instead of __detail::__common_iter_ptr.
-rw-r--r--libstdc++-v3/include/bits/iterator_concepts.h153
-rw-r--r--libstdc++-v3/include/bits/stl_iterator.h38
2 files changed, 97 insertions, 94 deletions
diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h
index 31b5840..e56abe2 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -320,84 +320,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Iter>
concept __iter_without_nested_types = !__iter_with_nested_types<_Iter>;
-
- // FIXME: These have to be at namespace-scope because of PR 92103.
- template<typename _Iter, bool __use_arrow = false>
- struct __ptr
- { using type = void; };
-
- template<typename _Iter> requires requires { typename _Iter::pointer; }
- struct __ptr<_Iter, true>
- { using type = typename _Iter::pointer; };
-
- template<typename _Iter> requires requires { typename _Iter::pointer; }
- struct __ptr<_Iter, false>
- { using type = typename _Iter::pointer; };
-
- template<typename _Iter>
- requires (!requires { typename _Iter::pointer; }
- && requires(_Iter& __it) { __it.operator->(); })
- struct __ptr<_Iter, true>
- { using type = decltype(std::declval<_Iter&>().operator->()); };
-
- template<typename _Iter>
- struct __ref
- { using type = iter_reference_t<_Iter>; };
-
- template<typename _Iter> requires requires { typename _Iter::reference; }
- struct __ref<_Iter>
- { using type = typename _Iter::reference; };
-
- template<typename _Iter>
- struct __cat
- { using type = input_iterator_tag; };
-
- template<typename _Iter>
- requires requires { typename _Iter::iterator_category; }
- struct __cat<_Iter>
- { using type = typename _Iter::iterator_category; };
-
- template<typename _Iter>
- requires (!requires { typename _Iter::iterator_category; }
- && __detail::__cpp17_randacc_iterator<_Iter>)
- struct __cat<_Iter>
- { using type = random_access_iterator_tag; };
-
- template<typename _Iter>
- requires (!requires { typename _Iter::iterator_category; }
- && __detail::__cpp17_bidi_iterator<_Iter>)
- struct __cat<_Iter>
- { using type = bidirectional_iterator_tag; };
-
- template<typename _Iter>
- requires (!requires { typename _Iter::iterator_category; }
- && __detail::__cpp17_fwd_iterator<_Iter>)
- struct __cat<_Iter>
- { using type = forward_iterator_tag; };
-
- template<typename _Iter>
- struct __diff
- { using type = void; };
-
- template<typename _Iter>
- requires requires {
- typename incrementable_traits<_Iter>::difference_type;
- }
- struct __diff<_Iter>
- {
- using type = typename incrementable_traits<_Iter>::difference_type;
- };
-
} // namespace __detail
template<typename _Iterator>
requires __detail::__iter_with_nested_types<_Iterator>
struct __iterator_traits<_Iterator, void>
{
+ private:
+ template<typename _Iter>
+ struct __ptr
+ { using type = void; };
+
+ template<typename _Iter> requires requires { typename _Iter::pointer; }
+ struct __ptr<_Iter>
+ { using type = typename _Iter::pointer; };
+
+ public:
using iterator_category = typename _Iterator::iterator_category;
using value_type = typename _Iterator::value_type;
using difference_type = typename _Iterator::difference_type;
- using pointer = typename __detail::__ptr<_Iterator>::type;
+ using pointer = typename __ptr<_Iterator>::type;
using reference = typename _Iterator::reference;
};
@@ -406,13 +348,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __detail::__cpp17_input_iterator<_Iterator>
struct __iterator_traits<_Iterator, void>
{
- using iterator_category = typename __detail::__cat<_Iterator>::type;
+ private:
+ template<typename _Iter>
+ struct __cat
+ { using type = input_iterator_tag; };
+
+ template<typename _Iter>
+ requires requires { typename _Iter::iterator_category; }
+ struct __cat<_Iter>
+ { using type = typename _Iter::iterator_category; };
+
+ template<typename _Iter>
+ requires (!requires { typename _Iter::iterator_category; }
+ && __detail::__cpp17_randacc_iterator<_Iter>)
+ struct __cat<_Iter>
+ { using type = random_access_iterator_tag; };
+
+ template<typename _Iter>
+ requires (!requires { typename _Iter::iterator_category; }
+ && __detail::__cpp17_bidi_iterator<_Iter>)
+ struct __cat<_Iter>
+ { using type = bidirectional_iterator_tag; };
+
+ template<typename _Iter>
+ requires (!requires { typename _Iter::iterator_category; }
+ && __detail::__cpp17_fwd_iterator<_Iter>)
+ struct __cat<_Iter>
+ { using type = forward_iterator_tag; };
+
+ template<typename _Iter>
+ struct __ptr
+ { using type = void; };
+
+ template<typename _Iter> requires requires { typename _Iter::pointer; }
+ struct __ptr<_Iter>
+ { using type = typename _Iter::pointer; };
+
+ template<typename _Iter>
+ requires (!requires { typename _Iter::pointer; }
+ && requires(_Iter& __it) { __it.operator->(); })
+ struct __ptr<_Iter>
+ { using type = decltype(std::declval<_Iter&>().operator->()); };
+
+ template<typename _Iter>
+ struct __ref
+ { using type = iter_reference_t<_Iter>; };
+
+ template<typename _Iter> requires requires { typename _Iter::reference; }
+ struct __ref<_Iter>
+ { using type = typename _Iter::reference; };
+
+ public:
+ using iterator_category = typename __cat<_Iterator>::type;
using value_type
= typename indirectly_readable_traits<_Iterator>::value_type;
using difference_type
= typename incrementable_traits<_Iterator>::difference_type;
- using pointer = typename __detail::__ptr<_Iterator, true>::type;
- using reference = typename __detail::__ref<_Iterator>::type;
+ using pointer = typename __ptr<_Iterator>::type;
+ using reference = typename __ref<_Iterator>::type;
};
template<typename _Iterator>
@@ -420,9 +413,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __detail::__cpp17_iterator<_Iterator>
struct __iterator_traits<_Iterator, void>
{
+ private:
+ template<typename _Iter>
+ struct __diff
+ { using type = void; };
+
+ template<typename _Iter>
+ requires requires
+ { typename incrementable_traits<_Iter>::difference_type; }
+ struct __diff<_Iter>
+ {
+ using type = typename incrementable_traits<_Iter>::difference_type;
+ };
+
+ public:
using iterator_category = output_iterator_tag;
using value_type = void;
- using difference_type = typename __detail::__diff<_Iterator>::type;
+ using difference_type = typename __diff<_Iterator>::type;
using pointer = void;
using reference = void;
};
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index b0f4549..7290781 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1903,29 +1903,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using difference_type = iter_difference_t<_It>;
};
- namespace __detail
- {
- // FIXME: This has to be at namespace-scope because of PR 92103.
- template<typename _It, typename _Sent>
- struct __common_iter_ptr
- {
- using type = void;
- };
-
- template<typename _It, typename _Sent>
- requires __detail::__common_iter_has_arrow<_It>
- struct __common_iter_ptr<_It, _Sent>
- {
- using common_iterator = std::common_iterator<_It, _Sent>;
-
- using type
- = decltype(std::declval<const common_iterator&>().operator->());
- };
- } // namespace __detail
-
template<input_iterator _It, typename _Sent>
struct iterator_traits<common_iterator<_It, _Sent>>
{
+ private:
+ template<typename _Iter>
+ struct __ptr
+ {
+ using type = void;
+ };
+
+ template<typename _Iter>
+ requires __detail::__common_iter_has_arrow<_Iter>
+ struct __ptr<_Iter>
+ {
+ using _CIter = common_iterator<_Iter, _Sent>;
+ using type = decltype(std::declval<const _CIter&>().operator->());
+ };
+
+ public:
using iterator_concept = conditional_t<forward_iterator<_It>,
forward_iterator_tag, input_iterator_tag>;
using iterator_category = __detail::__clamp_iter_cat<
@@ -1933,7 +1929,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
forward_iterator_tag, input_iterator_tag>;
using value_type = iter_value_t<_It>;
using difference_type = iter_difference_t<_It>;
- using pointer = typename __detail::__common_iter_ptr<_It, _Sent>::type;
+ using pointer = typename __ptr<_It>::type;
using reference = iter_reference_t<_It>;
};