This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] std::tr1::array testsuite additions, first attempt
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 21 Oct 2004 09:34:35 +0100
- Subject: Re: [v3] std::tr1::array testsuite additions, first attempt
- References: <20041020190047.093a91b7.bkoz@redhat.com>
> *************** 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)