This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Qualify less() and min() in basic_string.h


Paolo Carlini <pcarlini@unitus.it> writes:

| Hi,
| 
| same issue, different v3 file. Seems safe to me.
| 
| Tested x86-linux, if nobody complains will commit tomorrow.
| 
| Ciao, Paolo.
| 
| //////////////
| 2002-12-02  Paolo Carlini  <pcarlini@unitus.it>
| 
| 	* include/bits/basic_string.h
| 	(assign(const _CharT*, size_type), insert(size_type,
| 	const _CharT*, size_type), replace(size_type, size_type,
| 	const _CharT*, size_type)): Fully qualify less() with std::.
| 	(compare(const basic_string&)): Ditto for min().--- basic_string.h.~1.26.~	2002-09-11 01:19:10.000000000 +0200
| +++ basic_string.h	2002-12-02 01:30:50.000000000 +0100
| @@ -514,8 +514,8 @@
|        {
|  	if (__n > this->max_size())
|  	  __throw_length_error("basic_string::assign");
| -	if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
| -	    || less<const _CharT*>()(_M_data() + this->size(), __s))
| +	if (_M_rep()->_M_is_shared() || std::less<const _CharT*>()(__s, _M_data())
| +	    || std::less<const _CharT*>()(_M_data() + this->size(), __s))

This is unnecessary, but I guess it won't make any ill.  Koenig lookup
is not done on template-ids, and here there is no way it would resolve
to anything but std::less.  But your patch looks good.

At Santa Cruz Benjamin and I agreed that in this case, we should be
using our own "less" function objects -- crafted in our implementation
namespace.  I have a patch for that, but I'm waiting for mainline
unfreezing before applying it.

Basically, it reads:

   namespace __gnu_cxx
   {
      struct __less {
         template<typename _Tp>
           bool
           operator()(const _Tp& __x, const _Tp& __y) const
           { return __x < __y; }
      };
   }

We can use that to reduce to half the size of files like stl_algo_, base}.h
that duplicate codes.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]