[v3] std::tr1::array testsuite additions, first attempt
Jonathan Wakely
cow@compsoc.man.ac.uk
Thu Oct 21 08:34:00 GMT 2004
> *************** namespace tr1
> *** 161,167 ****
> template<typename _Tp, size_t _Nm>
> bool
> operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
> ! { return false; }
>
> template<typename _Tp, size_t _Nm>
> bool
> --- 164,174 ----
> template<typename _Tp, size_t _Nm>
> bool
> operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
> ! {
> ! bool __ret = __one.size() == __two.size();
> ! __ret &= std::equal(__one.begin(), __one.end(), __two.begin());
> ! return __ret;
> ! }
>
> template<typename _Tp, size_t _Nm>
> bool
Benjamin, is the size comparison pointless here, since both arrays have
the same _Nm ?
If it is needed, then the call to std::equal will go off the end of two
if two.size() < one.size() because it's called whether or not the sizes
are the same. Could use && to short circuit, but I think this is OK:
return std::equal(__one.begin(), __one.end(), __two.begin());
Not finished my coffee yet, so apologies if I'm missing something!
jon
--
"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil."
- Donald Knuth (paraphrasing Tony Hoare)
More information about the Libstdc++
mailing list