aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-01 12:38:29 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-08 11:26:40 +0000
commitb907cde027dc65af5842c06c50cfa12e2f58133b (patch)
treed6c497e9fc51053db87a1067a31b5f07cf3111c1
parent775056616386b7d05f81a413a0ad72c63aa381bf (diff)
downloadgcc-b907cde027dc65af5842c06c50cfa12e2f58133b.zip
gcc-b907cde027dc65af5842c06c50cfa12e2f58133b.tar.gz
gcc-b907cde027dc65af5842c06c50cfa12e2f58133b.tar.bz2
libstdc++: Simplify __detail::__distance_fw using 'if constexpr'
This uses 'if constexpr' instead of tag dispatching, removing the need for a second call using that tag, and simplifying the overload set that needs to be resolved for calls to __distance_fw. libstdc++-v3/ChangeLog: * include/bits/hashtable_policy.h (__distance_fw): Replace tag dispatching with 'if constexpr'.
-rw-r--r--libstdc++-v3/include/bits/hashtable_policy.h24
1 files changed, 10 insertions, 14 deletions
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index e5ad85e..ecf5031 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -62,25 +62,21 @@ namespace __detail
typename _Unused, typename _Traits>
struct _Hashtable_base;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
// Helper function: return distance(first, last) for forward
// iterators, or 0/1 for input iterators.
template<typename _Iterator>
inline typename std::iterator_traits<_Iterator>::difference_type
- __distance_fw(_Iterator __first, _Iterator __last,
- std::input_iterator_tag)
- { return __first != __last ? 1 : 0; }
-
- template<typename _Iterator>
- inline typename std::iterator_traits<_Iterator>::difference_type
- __distance_fw(_Iterator __first, _Iterator __last,
- std::forward_iterator_tag)
- { return std::distance(__first, __last); }
-
- template<typename _Iterator>
- inline typename std::iterator_traits<_Iterator>::difference_type
__distance_fw(_Iterator __first, _Iterator __last)
- { return __distance_fw(__first, __last,
- std::__iterator_category(__first)); }
+ {
+ using _Cat = typename std::iterator_traits<_Iterator>::iterator_category;
+ if constexpr (is_convertible<_Cat, forward_iterator_tag>::value)
+ return std::distance(__first, __last);
+ else
+ return __first != __last ? 1 : 0;
+ }
+#pragma GCC diagnostic pop
struct _Identity
{