⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vstring.h

📁 linux下编程用 编译软件
💻 H
📖 第 1 页 / 共 5 页
字号:
      length() const      { return this->_M_length(); }      /// Returns the size() of the largest possible %string.      size_type      max_size() const      { return this->_M_max_size(); }      /**       *  @brief  Resizes the %string to the specified number of characters.       *  @param  n  Number of characters the %string should contain.       *  @param  c  Character to fill any new elements.       *       *  This function will %resize the %string to the specified       *  number of characters.  If the number is smaller than the       *  %string's current size the %string is truncated, otherwise       *  the %string is extended and new elements are set to @a c.       */      void      resize(size_type __n, _CharT __c);      /**       *  @brief  Resizes the %string to the specified number of characters.       *  @param  n  Number of characters the %string should contain.       *       *  This function will resize the %string to the specified length.  If       *  the new size is smaller than the %string's current size the %string       *  is truncated, otherwise the %string is extended and new characters       *  are default-constructed.  For basic types such as char, this means       *  setting them to 0.       */      void      resize(size_type __n)      { this->resize(__n, _CharT()); }      /**       *  Returns the total number of characters that the %string can hold       *  before needing to allocate more memory.       */      size_type      capacity() const      { return this->_M_capacity(); }      /**       *  @brief  Attempt to preallocate enough memory for specified number of       *          characters.       *  @param  res_arg  Number of characters required.       *  @throw  std::length_error  If @a res_arg exceeds @c max_size().       *       *  This function attempts to reserve enough memory for the       *  %string to hold the specified number of characters.  If the       *  number requested is more than max_size(), length_error is       *  thrown.       *       *  The advantage of this function is that if optimal code is a       *  necessity and the user can determine the string length that will be       *  required, the user can reserve the memory in %advance, and thus       *  prevent a possible reallocation of memory and copying of %string       *  data.       */      void      reserve(size_type __res_arg = 0)      { this->_M_reserve(__res_arg); }      /**       *  Erases the string, making it empty.       */      void      clear()      { this->_M_erase(size_type(0), this->size()); }      /**       *  Returns true if the %string is empty.  Equivalent to *this == "".       */      bool      empty() const      { return this->size() == 0; }      // Element access:      /**       *  @brief  Subscript access to the data contained in the %string.       *  @param  pos  The index of the character to access.       *  @return  Read-only (constant) reference to the character.       *       *  This operator allows for easy, array-style, data access.       *  Note that data access with this operator is unchecked and       *  out_of_range lookups are not defined. (For checked lookups       *  see at().)       */      const_reference      operator[] (size_type __pos) const      {	_GLIBCXX_DEBUG_ASSERT(__pos <= this->size());	return this->_M_data()[__pos];      }      /**       *  @brief  Subscript access to the data contained in the %string.       *  @param  pos  The index of the character to access.       *  @return  Read/write reference to the character.       *       *  This operator allows for easy, array-style, data access.       *  Note that data access with this operator is unchecked and       *  out_of_range lookups are not defined. (For checked lookups       *  see at().)  Unshares the string.       */      reference      operator[](size_type __pos)      {	_GLIBCXX_DEBUG_ASSERT(__pos < this->size());	this->_M_leak();	return this->_M_data()[__pos];      }      /**       *  @brief  Provides access to the data contained in the %string.       *  @param n The index of the character to access.       *  @return  Read-only (const) reference to the character.       *  @throw  std::out_of_range  If @a n is an invalid index.       *       *  This function provides for safer data access.  The parameter is       *  first checked that it is in the range of the string.  The function       *  throws out_of_range if the check fails.       */      const_reference      at(size_type __n) const      {	if (__n >= this->size())	  std::__throw_out_of_range(__N("__versa_string::at"));	return this->_M_data()[__n];      }      /**       *  @brief  Provides access to the data contained in the %string.       *  @param n The index of the character to access.       *  @return  Read/write reference to the character.       *  @throw  std::out_of_range  If @a n is an invalid index.       *       *  This function provides for safer data access.  The parameter is       *  first checked that it is in the range of the string.  The function       *  throws out_of_range if the check fails.  Success results in       *  unsharing the string.       */      reference      at(size_type __n)      {	if (__n >= this->size())	  std::__throw_out_of_range(__N("__versa_string::at"));	this->_M_leak();	return this->_M_data()[__n];      }      // Modifiers:      /**       *  @brief  Append a string to this string.       *  @param str  The string to append.       *  @return  Reference to this string.       */      __versa_string&      operator+=(const __versa_string& __str)      { return this->append(__str); }      /**       *  @brief  Append a C string.       *  @param s  The C string to append.       *  @return  Reference to this string.       */      __versa_string&      operator+=(const _CharT* __s)      { return this->append(__s); }      /**       *  @brief  Append a character.       *  @param c  The character to append.       *  @return  Reference to this string.       */      __versa_string&      operator+=(_CharT __c)      { 	this->push_back(__c);	return *this;      }      /**       *  @brief  Append a string to this string.       *  @param str  The string to append.       *  @return  Reference to this string.       */      __versa_string&      append(const __versa_string& __str)      { return _M_append(__str._M_data(), __str.size()); }      /**       *  @brief  Append a substring.       *  @param str  The string to append.       *  @param pos  Index of the first character of str to append.       *  @param n  The number of characters to append.       *  @return  Reference to this string.       *  @throw  std::out_of_range if @a pos is not a valid index.       *       *  This function appends @a n characters from @a str starting at @a pos       *  to this string.  If @a n is is larger than the number of available       *  characters in @a str, the remainder of @a str is appended.       */      __versa_string&      append(const __versa_string& __str, size_type __pos, size_type __n)      { return _M_append(__str._M_data()			 + __str._M_check(__pos, "__versa_string::append"),			 __str._M_limit(__pos, __n)); }      /**       *  @brief  Append a C substring.       *  @param s  The C string to append.       *  @param n  The number of characters to append.       *  @return  Reference to this string.       */      __versa_string&      append(const _CharT* __s, size_type __n)      {	__glibcxx_requires_string_len(__s, __n);	_M_check_length(size_type(0), __n, "__versa_string::append");	return _M_append(__s, __n);      }      /**       *  @brief  Append a C string.       *  @param s  The C string to append.       *  @return  Reference to this string.       */      __versa_string&      append(const _CharT* __s)      {	__glibcxx_requires_string(__s);	const size_type __n = traits_type::length(__s);	_M_check_length(size_type(0), __n, "__versa_string::append");	return _M_append(__s, __n);      }      /**       *  @brief  Append multiple characters.       *  @param n  The number of characters to append.       *  @param c  The character to use.       *  @return  Reference to this string.       *       *  Appends n copies of c to this string.       */      __versa_string&      append(size_type __n, _CharT __c)      { return _M_replace_aux(this->size(), size_type(0), __n, __c); }      /**       *  @brief  Append a range of characters.       *  @param first  Iterator referencing the first character to append.       *  @param last  Iterator marking the end of the range.       *  @return  Reference to this string.       *       *  Appends characters in the range [first,last) to this string.       */      template<class _InputIterator>        __versa_string&        append(_InputIterator __first, _InputIterator __last)        { return this->replace(_M_iend(), _M_iend(), __first, __last); }      /**       *  @brief  Append a single character.       *  @param c  Character to append.       */      void      push_back(_CharT __c)      { 	const size_type __size = this->size();	if (__size + 1 > this->capacity() || this->_M_is_shared())	  this->_M_mutate(__size, size_type(0), 0, size_type(1));	traits_type::assign(this->_M_data()[__size], __c);	this->_M_set_length(__size + 1);      }      /**       *  @brief  Set value to contents of another string.       *  @param  str  Source string to use.       *  @return  Reference to this string.       */      __versa_string&      assign(const __versa_string& __str)      {	this->_M_assign(__str);	return *this;      }      /**       *  @brief  Set value to a substring of a string.       *  @param str  The string to use.       *  @param pos  Index of the first character of str.       *  @param n  Number of characters to use.       *  @return  Reference to this string.       *  @throw  std::out_of_range if @a pos is not a valid index.       *       *  This function sets this string to the substring of @a str consisting       *  of @a n characters at @a pos.  If @a n is is larger than the number       *  of available characters in @a str, the remainder of @a str is used.       */      __versa_string&      assign(const __versa_string& __str, size_type __pos, size_type __n)      { return _M_replace(size_type(0), this->size(), __str._M_data()			  + __str._M_check(__pos, "__versa_string::assign"),			  __str._M_limit(__pos, __n)); }      /**       *  @brief  Set value to a C substring.       *  @param s  The C string to use.       *  @param n  Number of characters to use.       *  @return  Reference to this string.       *       *  This function sets the value of this string to the first @a n       *  characters of @a s.  If @a n is is larger than the number of       *  available characters in @a s, the remainder of @a s is used.       */      __versa_string&      assign(const _CharT* __s, size_type __n)      {	__glibcxx_requires_string_len(__s, __n);	return _M_replace(size_type(0), this->size(), __s, __n);      }      /**       *  @brief  Set value to contents of a C string.       *  @param s  The C string to use.       *  @return  Reference to this string.       *       *  This function sets the value of this string to the value of @a s.       *  The data is copied, so there is no dependence on @a s once the       *  function returns.       */      __versa_string&      assign(const _CharT* __s)      {	__glibcxx_requires_string(__s);	return _M_replace(size_type(0), this->size(), __s,			  traits_type::length(__s));      }      /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -