]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Simplify std::basic_regex::assign
authorJonathan Wakely <jwakely@redhat.com>
Mon, 11 Oct 2021 16:19:43 +0000 (17:19 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 11 Oct 2021 19:35:45 +0000 (20:35 +0100)
We know that if __is_contiguous_iterator is true then we have a pointer
or a __normal_iterator that wraps a pointer, so we don't need to use
std::__to_address.

libstdc++-v3/ChangeLog:

* include/bits/regex.h (basic_regex::assign(Iter, Iter)): Avoid
std::__to_address by using poitner directly or using base()
member of __normal_iterator.

libstdc++-v3/include/bits/regex.h

index 3c44bcd7e33f86843040beaaddcf9e7d251011a2..a3990183580a84047e25e9a255765d235924d7bf 100644 (file)
@@ -682,15 +682,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        assign(_InputIterator __first, _InputIterator __last,
               flag_type __flags = ECMAScript)
        {
-#if __cplusplus >= 201703L
+#if __cpp_if_constexpr >= 201606L
          using _ValT = typename iterator_traits<_InputIterator>::value_type;
          if constexpr (__detail::__is_contiguous_iter<_InputIterator>::value
                        && is_same_v<_ValT, value_type>)
            {
              __glibcxx_requires_valid_range(__first, __last);
-             const auto __len = __last - __first;
-             const _Ch_type* __p = std::__to_address(__first);
-             _M_compile(__p, __p + __len, __flags);
+             if constexpr (is_pointer_v<_InputIterator>)
+               _M_compile(__first, __last, __flags);
+             else // __normal_iterator<_T*, C>
+               _M_compile(__first.base(), __last.base(), __flags);
            }
          else
 #endif