basic_string<> - operator+

Benjamin Kosnik bkoz@cygnus.com
Fri Jun 25 01:40:00 GMT 1999


> My proposal:
> create an empty string -> call reserve -> append __lhs -> append __rhs.

. . . does not avoid the call to _M_mutate in the case of const _CharT*: I
don't see any advantage, and an added complexity. Time it in a loop: I
believe you'll agree with me.

This may be a win though, in the case of the single _CharT:

  template<typename _CharT, typename _Traits, typename _Alloc>
    inline basic_string<_CharT, _Traits, _Alloc>
    operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>&
__rhs)
    {
      basic_string<_CharT, _Traits, _Alloc> __str(__rhs);
      __str.insert(__str.begin(), __lhs);
      return __str;
    }
 
-benjamin



More information about the Libstdc++ mailing list