http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50661
Bug #: 50661 Summary: std::equal should use more efficient version for arrays of pointers Classification: Unclassified Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: e...@wojak.eu The following program uses the generic comparison algorithm in bits/stl_algobase.h, while it could use the template specialization using __builtin_memcmp instead. #include <iostream> #include <boost/array.hpp> int main() { boost::array<void*, 888> a, b; bool res = std::equal(a.begin(), a.begin() + 50, b.begin()); return 0; } I checked with gcc-4.4.5, but I saw it's the same in SVN trunk. The following patch solves this issue. --- /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4/bits/stl_algobase.h 2011-09-07 16:34:35.581681814 +0200 +++ /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4/bits/stl_algobase.h 2011-10-08 01:09:44.987380358 +0200 @@ -823,7 +823,7 @@ { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value + const bool __simple = ((__is_integer<_ValueType1>::__value || __is_pointer<_ValueType1>::__value) && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value);