// Components for manipulating sequences of characters -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2008, 2009
+// 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
* @class basic_string basic_string.h <string>
* @brief Managing sequences of characters and character-like objects.
*
+ * @ingroup strings
* @ingroup sequences
*
* Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#66">reversible container</a>, and a
* <a href="tables.html#67">sequence</a>. Of the
* <a href="tables.html#68">optional sequence requirements</a>, only
- * @c push_back, @c at, and array access are supported.
+ * @c push_back, @c at, and @c %array access are supported.
*
* @doctodo
*
* This approach has the enormous advantage that a string object
* requires only one allocation. All the ugliness is confined
* within a single pair of inline functions, which each compile to
- * a single "add" instruction: _Rep::_M_data(), and
+ * a single @a add instruction: _Rep::_M_data(), and
* string::_M_rep(); and the allocation function which gets a
* block of raw bytes and with room enough and constructs a _Rep
* object at the front.
* string length.)
*
* Note that the _Rep object is a POD so that you can have a
- * static "empty string" _Rep object already "constructed" before
+ * static <em>empty string</em> _Rep object already @a constructed before
* static constructors have run. The reference-count encoding is
* chosen so that a 0 indicates one reference, so you never try to
* destroy the empty-string _Rep object.
/**
* @brief Default constructor creates an empty string.
*/
- inline
- basic_string();
+ basic_string()
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
+ : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
+#else
+ : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ }
+#endif
/**
* @brief Construct an empty string using allocator @a a.
* @param n Number of characters to copy.
* @param a Allocator to use (default is default allocator).
*
- * NB: @a s must have at least @a n characters, '\\0' has no special
- * meaning.
+ * NB: @a s must have at least @a n characters, '\\0'
+ * has no special meaning.
*/
basic_string(const _CharT* __s, size_type __n,
const _Alloc& __a = _Alloc());
#ifdef __GXX_EXPERIMENTAL_CXX0X__
/**
+ * @brief Move construct string.
+ * @param str Source string.
+ *
+ * The newly-created string contains the exact contents of @a str.
+ * @a str is a valid, but unspecified string.
+ **/
+ basic_string(basic_string&& __str)
+ : _M_dataplus(__str._M_dataplus)
+ {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
+ __str._M_data(_S_empty_rep()._M_refdata());
+#else
+ __str._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
+#endif
+ }
+
+ /**
* @brief Construct string from an initializer list.
* @param l std::initializer_list of characters.
* @param a Allocator to use (default is default allocator).
#ifdef __GXX_EXPERIMENTAL_CXX0X__
/**
+ * @brief Move assign the value of @a str to this string.
+ * @param str Source string.
+ *
+ * The contents of @a str are moved into this string (without copying).
+ * @a str is a valid, but unspecified string.
+ **/
+ basic_string&
+ operator=(basic_string&& __str)
+ {
+ // NB: DR 1204.
+ this->swap(__str);
+ return *this;
+ }
+
+ /**
* @brief Set value to string constructed from initializer list.
* @param l std::initializer_list.
*/
length() const
{ return _M_rep()->_M_length; }
- /// Returns the size() of the largest possible %string.
+ /// Returns the size() of the largest possible %string.
size_type
max_size() const
{ return _Rep::_S_max_size; }
resize(size_type __n)
{ this->resize(__n, _CharT()); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /// A non-binding request to reduce capacity() to size().
+ void
+ shrink_to_fit()
+ {
+ __try
+ { reserve(0); }
+ __catch(...)
+ { }
+ }
+#endif
+
/**
* Returns the total number of characters that the %string can hold
* before needing to allocate more memory.
{ _M_mutate(0, this->size(), 0); }
/**
- * Returns true if the %string is empty. Equivalent to *this == "".
+ * Returns true if the %string is empty. Equivalent to
+ * <code>*this == ""</code>.
*/
bool
empty() const
basic_string&
assign(const basic_string& __str);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /**
+ * @brief Set value to contents of another string.
+ * @param str Source string to use.
+ * @return Reference to this string.
+ *
+ * This function sets this string to the exact contents of @a str.
+ * @a str is a valid, but unspecified string.
+ */
+ basic_string&
+ assign(basic_string&& __str)
+ {
+ this->swap(__str);
+ return *this;
+ }
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
/**
* @brief Set value to a substring of a string.
* @param str The string to use.
* @throw std::length_error If new length exceeds @c max_size().
*
* Removes the characters in the range [pos,pos + n1) from this string.
- * In place, the first @a n characters of @a s are inserted. If @a
- * pos is beyond end of string, out_of_range is thrown. If the length
- * of result exceeds max_size(), length_error is thrown. The value of
- * the string doesn't change if an error is thrown.
+ * In place, the characters of @a s are inserted. If @a pos is beyond
+ * end of string, out_of_range is thrown. If the length of result
+ * exceeds max_size(), length_error is thrown. The value of the string
+ * doesn't change if an error is thrown.
*/
basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s)
static _CharT*
_S_construct_aux(_Integer __beg, _Integer __end,
const _Alloc& __a, __true_type)
- { return _S_construct(static_cast<size_type>(__beg),
- static_cast<value_type>(__end), __a); }
+ { return _S_construct_aux_2(static_cast<size_type>(__beg),
+ __end, __a); }
+
+ static _CharT*
+ _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a)
+ { return _S_construct(__req, __c, __a); }
template<class _InIterator>
static _CharT*
* result of the comparison is nonzero returns it, otherwise the shorter
* one is ordered first.
*
- * NB: s must have at least n2 characters, '\\0' has no special
- * meaning.
+ * NB: s must have at least n2 characters, '\\0' has
+ * no special meaning.
*/
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2) const;
};
- template<typename _CharT, typename _Traits, typename _Alloc>
- inline basic_string<_CharT, _Traits, _Alloc>::
- basic_string()
-#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
- : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
-#else
- : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
-#endif
-
// operator+
/**
* @brief Concatenate two strings.
* @param str Buffer to store into.
* @return Reference to the input stream.
*
- * Stores characters from is into @a str until '\n' is found, the end of
- * the stream is encountered, or str.max_size() is reached. If is.width()
- * is non-zero, that is the limit on the number of characters stored into
- * @a str. Any previous contents of @a str are erased. If end of line was
- * encountered, it is extracted but not stored into @a str.
+ * Stores characters from is into @a str until '\n' is
+ * found, the end of the stream is encountered, or str.max_size()
+ * is reached. If is.width() is non-zero, that is the limit on the
+ * number of characters stored into @a str. Any previous contents
+ * of @a str are erased. If end of line was encountered, it is
+ * extracted but not stored into @a str.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
inline basic_istream<_CharT, _Traits>&
_GLIBCXX_END_NAMESPACE
+#endif /* __GXX_EXPERIMENTAL_CXX0X__ && _GLIBCXX_USE_C99 ... */
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+#include <bits/functional_hash.h>
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ // DR 1182.
+
+#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
+ /// std::hash specialization for string.
+ template<>
+ struct hash<string>
+ : public std::unary_function<string, size_t>
+ {
+ size_t
+ operator()(const string& __s) const
+ { return std::_Fnv_hash::hash(__s.data(), __s.length()); }
+ };
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ /// std::hash specialization for wstring.
+ template<>
+ struct hash<wstring>
+ : public std::unary_function<wstring, size_t>
+ {
+ size_t
+ operator()(const wstring& __s) const
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(wchar_t)); }
+ };
+#endif
+#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ /// std::hash specialization for u16string.
+ template<>
+ struct hash<u16string>
+ : public std::unary_function<u16string, size_t>
+ {
+ size_t
+ operator()(const u16string& __s) const
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char16_t)); }
+ };
+
+ /// std::hash specialization for u32string.
+ template<>
+ struct hash<u32string>
+ : public std::unary_function<u32string, size_t>
+ {
+ size_t
+ operator()(const u32string& __s) const
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char32_t)); }
+ };
#endif
+_GLIBCXX_END_NAMESPACE
+
+#endif /* __GXX_EXPERIMENTAL_CXX0X__ */
+
#endif /* _BASIC_STRING_H */