Hi,

On 08/29/2013 09:37 PM, François Dumont wrote:
Indeed, I check the Standard about const_pointer, so here is another attempt.

Tested under Linux x86_64.

2013-08-29  François Dumont  <fdum...@gcc.gnu.org>

    PR libstdc++/58148
    * include/debug/functions.h (__foreign_iterator_aux4): Use
    sequence const_pointer as common type to compare pointers. Add a
    fallback overload in case pointers cannot be cast to sequence
    const_pointer.
    * testsuite/23_containers/vector/modifiers/insert/58148.cc: New.

Ok to commit ?
Seems pretty good to me. I have been thinking: when the non-trivial __foreign_iterator_aux4 is selected it actually has available as the last two arguments

    std::addressof(*(__it._M_get_sequence()->_M_base().begin()))
    std::addressof(*__other)

we could as well give the parameters names and avoid passing __other. Also, I think we can do everything with std::less. I'm attaching below something I quickly hacked, untested, see if you like it in case commit something similar.

Thanks!
Paolo.

//////////////////////
Index: functions.h
===================================================================
--- functions.h (revision 202068)
+++ functions.h (working copy)
@@ -36,7 +36,7 @@
 #include <bits/move.h>                    // for __addressof and addressof
 #if __cplusplus >= 201103L
 # include <bits/stl_function.h>                  // for less and greater_equal
-# include <type_traits>                          // for common_type
+# include <type_traits>                          // for is_lvalue_reference 
and __and_
 #endif
 #include <debug/formatter.h>
 
@@ -172,27 +172,28 @@
     }
 
 #if __cplusplus >= 201103L
-  template<typename _Iterator, typename _Sequence,
-          typename _InputIterator,
-          typename _PointerType1,
-          typename _PointerType2>
+  // Default implementation.
+  template<typename _Iterator, typename _Sequence>
     inline bool
     __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>& __it,
-                           _InputIterator __other,
-                           _PointerType1, _PointerType2)
+                           typename _Sequence::const_pointer __begin,
+                           typename _Sequence::const_pointer __other)
     {
-      typedef typename std::common_type<_PointerType1,
-                                       _PointerType2>::type _PointerType;
+      typedef typename _Sequence::const_pointer _PointerType;
       constexpr std::less<_PointerType> __l{};
-      constexpr std::greater_equal<_PointerType> __ge{};
 
-      return (__l(std::addressof(*__other),
-                 std::addressof(*(__it._M_get_sequence()->_M_base().begin())))
-             || __ge(std::addressof(*__other),
-                     std::addressof(*(__it._M_get_sequence()->_M_base().end()
-                                      - 1)) + 1));
+      return (__l(__other, __begin)
+             || __l(std::addressof(*(__it._M_get_sequence()->_M_base().end()
+                                     - 1)), __other));
     }
-                         
+
+  // Fallback when address type cannot be implicitely casted to sequence
+  // const_pointer.
+  template<typename _Iterator, typename _Sequence>
+    inline bool
+    __foreign_iterator_aux4(const _Safe_iterator<_Iterator, _Sequence>&, ...)
+    { return true; }
+
   template<typename _Iterator, typename _Sequence, typename _InputIterator>
     inline bool
     __foreign_iterator_aux3(const _Safe_iterator<_Iterator, _Sequence>& __it,
@@ -209,12 +210,12 @@
            - std::addressof(*(__it._M_get_sequence()->_M_base().begin()))
            == __it._M_get_sequence()->size() - 1)
          return (__foreign_iterator_aux4
-                 (__it, __other,
+                 (__it,
                   std::addressof(*(__it._M_get_sequence()->_M_base().begin())),
                   std::addressof(*__other)));
       return true;
     }
-                          
+   
   /* Fallback overload for which we can't say, assume it is valid. */
   template<typename _Iterator, typename _Sequence, typename _InputIterator>
     inline bool
@@ -223,7 +224,7 @@
                            std::false_type)
     { return true; }
 #endif
-                          
+
   /** Checks that iterators do not belong to the same sequence. */
   template<typename _Iterator, typename _Sequence, typename _OtherIterator>
     inline bool

Reply via email to