[patch] C++14: N3671 Making non-modifying sequence operations more robust
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Jun 10 23:10:00 GMT 2013
On 10 June 2013 21:16, François Dumont wrote:
> @@ -810,6 +823,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> return !__builtin_memcmp(__first1, __first2, sizeof(_Tp)
> * (__last1 - __first1));
> }
> +
> +#if __cplusplus > 201103L
> + template<typename _Tp>
> + static bool
> + equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2,
> + const _Tp* __last2)
> + {
> + return !__builtin_memcmp(__first1, __first2, sizeof(_Tp)
> + * (__last1 - __first1));
> + }
> +#endif
> };
>
> I think there is a problem here. I had a closer look because __last2 is not
> consider in the version taking pointers.
Oops, yes, I copied the existing code then didn't update it.
> We could start reading after
> __last2, something Valgrin could catch perhaps. A consistent version would
> be:
>
> +#if __cplusplus > 201103L
> + template<typename _Tp>
> + static bool
> + equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2,
> + const _Tp* __last2)
> + {
> + if (__builtin_memcmp(__first1, __first2, sizeof(_Tp)
> + * std::min(__last1 - __first1, __last2 -
> __first2))
> + return false;
> + return true;
> + }
> +#endif
>
> But I am not sure it is the intended behavior because I can't see where
> those equal overloads are used. It looks like __equal2 has been implemented
> and used instead. Maybe some dead code to clean, no ?
It should be used, I'll check it.
More information about the Libstdc++
mailing list