diff options
author | Jason Merrill <jason@redhat.com> | 2008-07-21 15:40:39 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2008-07-21 15:40:39 -0400 |
commit | 988499f434108234543101579471a2fb25bf537f (patch) | |
tree | efdfd86136a070108ac69fda382332c5475473a6 /libstdc++-v3/include | |
parent | 39a13be5cbfe0e9623782de3733cd8265e6230d4 (diff) | |
download | gcc-988499f434108234543101579471a2fb25bf537f.zip gcc-988499f434108234543101579471a2fb25bf537f.tar.gz gcc-988499f434108234543101579471a2fb25bf537f.tar.bz2 |
Add initializer_list support as per N2679.
* include/debug/unordered_map: Add initializer_list support.
* include/debug/safe_association.h: Likewise.
* include/debug/unordered_set: Likewise.
* include/debug/vector: Likewise.
* include/debug/deque: Likewise.
* include/debug/map.h: Likewise.
* include/debug/set.h: Likewise.
* include/debug/string: Likewise.
* include/debug/list: Likewise.
* include/debug/multimap.h: Likewise.
* include/tr1_impl/unordered_map: Likewise.
* include/tr1_impl/hashtable: Likewise.
* include/tr1_impl/unordered_set: Likewise.
* include/tr1_impl/regex: Likewise.
* include/std/valarray: Likewise.
* include/std/unordered_map: Likewise.
* include/std/unordered_set: Likewise.
* include/bits/stl_list.h: Likewise.
* include/bits/stl_map.h: Likewise.
* include/bits/stl_set.h: Likewise.
* include/bits/basic_string.h: Likewise.
* include/bits/basic_string.tcc: Likewise.
* include/bits/stl_multimap.h: Likewise.
* include/bits/stl_vector.h: Likewise.
* include/bits/stl_deque.h: Likewise.
* include/bits/stl_multiset.h: Likewise.
* include/bits/stl_bvector.h: Likewise.
* include/ext/vstring.h: Likewise.
* include/ext/rc_string_base.h: Likewise.
* include/ext/sso_string_base.h: Likewise.
* src/Makefile.am (w?string-inst): Build with -std=gnu++0x.
* src/Makefile.in: Likewise.
* config/abi/pre/gnu.ver: Add new w?string exports.
...
From-SVN: r138043
Diffstat (limited to 'libstdc++-v3/include')
31 files changed, 1014 insertions, 2 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 19c79d1..de4cf80 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -45,6 +45,7 @@ #include <ext/atomicity.h> #include <debug/debug.h> +#include <initializer_list> _GLIBCXX_BEGIN_NAMESPACE(std) @@ -477,6 +478,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) */ basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Construct string from an initializer list. + * @param l std::initializer_list of characters. + * @param a Allocator to use (default is default allocator). + */ + basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Construct string as copy of a range. * @param beg Start of range. @@ -523,6 +533,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Set value to string constructed from initializer list. + * @param l std::initializer_list. + */ + basic_string& + operator=(initializer_list<_CharT> __l) + { + this->assign (__l.begin(), __l.end()); + return *this; + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + // Iterators: /** * Returns a read/write iterator that points to the first character in @@ -794,6 +817,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Append an initializer_list of characters. + * @param l The initializer_list of characters to be appended. + * @return Reference to this string. + */ + basic_string& + operator+=(initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Append a string to this string. * @param str The string to append. @@ -849,6 +883,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) basic_string& append(size_type __n, _CharT __c); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Append an initializer_list of characters. + * @param l The initializer_list of characters to append. + * @return Reference to this string. + */ + basic_string& + append(initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Append a range of characters. * @param first Iterator referencing the first character to append. @@ -957,6 +1002,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) assign(_InputIterator __first, _InputIterator __last) { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Set value to an initializer_list of characters. + * @param l The initializer_list of characters to assign. + * @return Reference to this string. + */ + basic_string& + assign(initializer_list<_CharT> __l) + { return this->assign(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Insert multiple characters. * @param p Iterator referencing location in string to insert at. @@ -989,6 +1045,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std) insert(iterator __p, _InputIterator __beg, _InputIterator __end) { this->replace(__p, __p, __beg, __end); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Insert an initializer_list of characters. + * @param p Iterator referencing location in string to insert at. + * @param l The initializer_list of characters to insert. + * @throw std::length_error If new length exceeds @c max_size(). + */ + void + insert(iterator __p, initializer_list<_CharT> __l) + { this->insert(__p, __l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Insert value of a string. * @param pos1 Iterator referencing location in string to insert at. @@ -1434,6 +1502,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __k1.base(), __k2 - __k1); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Replace range of characters with initializer_list. + * @param i1 Iterator referencing start of range to replace. + * @param i2 Iterator referencing end of range to replace. + * @param l The initializer_list of characters to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, characters + * in the range [k1,k2) are inserted. 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(iterator __i1, iterator __i2, + initializer_list<_CharT> __l) + { return this->replace(__i1, __i2, __l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + private: template<class _Integer> basic_string& diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 49b6494..3201e36 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -235,6 +235,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _M_dataplus(_S_construct(__beg, __end, __a), __a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>:: + basic_string(initializer_list<_CharT> __l, const _Alloc& __a) + : _M_dataplus(_S_construct(__l.begin(), __l.end(), __a), __a) + { } +#endif + template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>:: diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 045f203..ad0ed87 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -62,6 +62,8 @@ #ifndef _STL_BVECTOR_H #define _STL_BVECTOR_H 1 +#include <initializer_list> + _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) typedef unsigned long _Bit_type; @@ -529,6 +531,14 @@ template<typename _Alloc> #ifdef __GXX_EXPERIMENTAL_CXX0X__ vector(vector&& __x) : _Base(std::forward<_Base>(__x)) { } + + vector(initializer_list<bool> __l, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + _M_initialize_range(__l.begin(), __l.end(), + random_access_iterator_tag()); + } #endif template<typename _InputIterator> @@ -566,6 +576,13 @@ template<typename _Alloc> this->swap(__x); return *this; } + + vector& + operator=(initializer_list<bool> __l) + { + this->assign (__l.begin(), __l.end()); + return *this; + } #endif // assign(), a generalized assignment member function. Two @@ -584,6 +601,12 @@ template<typename _Alloc> _M_assign_dispatch(__first, __last, _Integral()); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + assign(initializer_list<bool> __l) + { this->assign(__l.begin(), __l.end()); } +#endif + iterator begin() { return this->_M_impl._M_start; } @@ -777,6 +800,11 @@ template<typename _Alloc> insert(iterator __position, size_type __n, const bool& __x) { _M_fill_insert(__position, __n, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void insert(iterator __p, initializer_list<bool> __l) + { this->insert(__p, __l.begin(), __l.end()); } +#endif + void pop_back() { --this->_M_impl._M_finish; } diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index b778f15..070fc07 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -65,6 +65,7 @@ #include <bits/concept_check.h> #include <bits/stl_iterator_base_types.h> #include <bits/stl_iterator_base_funcs.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -740,6 +741,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ deque(deque&& __x) : _Base(std::forward<_Base>(__x)) { } + + /** + * @brief Builds a %deque from an initializer list. + * @param l An initializer_list. + * @param a An allocator object. + * + * Create a %deque consisting of copies of the elements in the + * initializer_list @a l. + * + * This will call the element type's copy constructor N times + * (where N is l.size()) and do no memory reallocation. + */ + deque(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + _M_range_initialize(__l.begin(), __l.end(), + random_access_iterator_tag()); + } #endif /** @@ -801,6 +821,24 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief Assigns an initializer list to a %deque. + * @param l An initializer_list. + * + * This function fills a %deque with copies of the elements in the + * initializer_list @a l. + * + * Note that the assignment completely changes the %deque and that the + * resulting %deque's size is the same as the number of elements + * assigned. Old data may be lost. + */ + deque& + operator=(initializer_list<value_type> __l) + { + this->assign(__l.begin(), __l.end()); + return *this; + } #endif /** @@ -837,6 +875,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_assign_dispatch(__first, __last, _Integral()); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Assigns an initializer list to a %deque. + * @param l An initializer_list. + * + * This function fills a %deque with copies of the elements in the + * initializer_list @a l. + * + * Note that the assignment completely changes the %deque and that the + * resulting %deque's size is the same as the number of elements + * assigned. Old data may be lost. + */ + void + assign(initializer_list<value_type> __l) + { this->assign(__l.begin(), __l.end()); } +#endif + /// Get a copy of the memory allocation object. allocator_type get_allocator() const @@ -1253,6 +1308,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) iterator insert(iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } + + /** + * @brief Inserts an initializer list into the %deque. + * @param p An iterator into the %deque. + * @param l An initializer_list. + * + * This function will insert copies of the data in the + * initializer_list @a l into the %deque before the location + * specified by @a p. This is known as "list insert." + */ + void + insert(iterator __p, initializer_list<value_type> __l) + { this->insert(__p, __l.begin(), __l.end()); } #endif /** diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 08fb89e..b38fa55 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -63,6 +63,7 @@ #define _STL_LIST_H 1 #include <bits/concept_check.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -541,6 +542,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ list(list&& __x) : _Base(std::forward<_Base>(__x)) { } + + /** + * @brief Builds a %list from an initializer_list + * @param l An initializer_list of value_type. + * @param a An allocator object. + * + * Create a %list consisting of copies of the elements in the + * initializer_list @a l. This is linear in l.size(). + */ + list(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); } #endif /** @@ -597,6 +611,20 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %List initializer list assignment operator. + * @param l An initializer_list of value_type. + * + * Replace the contents of the %list with copies of the elements + * in the initializer_list @a l. This is linear in l.size(). + */ + list& + operator=(initializer_list<value_type> __l) + { + this->assign(__l.begin(), __l.end()); + return *this; + } #endif /** @@ -634,6 +662,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_assign_dispatch(__first, __last, _Integral()); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Assigns an initializer_list to a %list. + * @param l An initializer_list of value_type. + * + * Replace the contents of the %list with copies of the elements + * in the initializer_list @a l. This is linear in l.size(). + */ + void + assign(initializer_list<value_type> __l) + { this->assign(__l.begin(), __l.end()); } +#endif + /// Get a copy of the memory allocation object. allocator_type get_allocator() const @@ -951,6 +992,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) iterator insert(iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } + + /** + * @brief Inserts the contents of an initializer_list into %list + * before specified iterator. + * @param p An iterator into the %list. + * @param l An initializer_list of value_type. + * + * This function will insert copies of the data in the + * initializer_list @a l into the %list before the location + * specified by @a p. + * + * This operation is linear in the number of elements inserted and + * does not invalidate iterators and references. + */ + void + insert(iterator __p, initializer_list<value_type> __l) + { this->insert(__p, __l.begin(), __l.end()); } #endif /** diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index cd85b9a..b402b82 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -186,6 +186,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ map(map&& __x) : _M_t(std::forward<_Rep_type>(__x._M_t)) { } + + /** + * @brief Builds a %map from an initializer_list. + * @param l An initializer_list. + * @param comp A comparison object. + * @param a An allocator object. + * + * Create a %map consisting of copies of the elements in the + * initializer_list @a l. + * This is linear in N if the range is already sorted, and NlogN + * otherwise (where N is @a l.size()). + */ + map(initializer_list<value_type> __l, + const _Compare& __c = _Compare(), + const allocator_type& __a = allocator_type()) + : _M_t(__c, __a) + { _M_t._M_insert_unique(__l.begin(), __l.end()); } #endif /** @@ -259,6 +276,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %Map list assignment operator. + * @param l An initializer_list. + * + * This function fills a %map with copies of the elements in the + * initializer list @a l. + * + * Note that the assignment completely changes the %map and + * that the resulting %map's size is the same as the number + * of elements assigned. Old data may be lost. + */ + map& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif /// Get a copy of the memory allocation object. @@ -476,7 +512,6 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * inserted. * * Complexity similar to that of the range constructor. - * */ void insert(std::initializer_list<value_type> __list) diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index ade2750..0834c95 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -63,6 +63,7 @@ #define _STL_MULTIMAP_H 1 #include <bits/concept_check.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -183,6 +184,22 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ multimap(multimap&& __x) : _M_t(std::forward<_Rep_type>(__x._M_t)) { } + + /** + * @brief Builds a %multimap from an initializer_list. + * @param l An initializer_list. + * @param comp A comparison functor. + * @param a An allocator object. + * + * Create a %multimap consisting of copies of the elements from + * the initializer_list. This is linear in N if the list is already + * sorted, and NlogN otherwise (where N is @a __l.size()). + */ + multimap(initializer_list<value_type> __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _M_t(__comp, __a) + { _M_t._M_insert_equal(__l.begin(), __l.end()); } #endif /** @@ -256,6 +273,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %Multimap list assignment operator. + * @param l An initializer_list. + * + * This function fills a %multimap with copies of the elements + * in the initializer list @a l. + * + * Note that the assignment completely changes the %multimap and + * that the resulting %multimap's size is the same as the number + * of elements assigned. Old data may be lost. + */ + multimap& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif /// Get a copy of the memory allocation object. @@ -444,6 +480,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) insert(_InputIterator __first, _InputIterator __last) { _M_t._M_insert_equal(__first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Attempts to insert a list of std::pairs into the %multimap. + * @param list A std::initializer_list<value_type> of pairs to be + * inserted. + * + * Complexity similar to that of the range constructor. + */ + void + insert(initializer_list<value_type> __l) + { this->insert(__l.begin(), __l.end()); } +#endif + /** * @brief Erases an element from a %multimap. * @param position An iterator pointing to the element to be erased. diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index 2cdbdfe..2fea83f 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -63,6 +63,7 @@ #define _STL_MULTISET_H 1 #include <bits/concept_check.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -196,6 +197,22 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ multiset(multiset&& __x) : _M_t(std::forward<_Rep_type>(__x._M_t)) { } + + /** + * @brief Builds a %multiset from an initializer_list. + * @param l An initializer_list. + * @param comp A comparison functor. + * @param a An allocator object. + * + * Create a %multiset consisting of copies of the elements from + * the list. This is linear in N if the list is already sorted, + * and NlogN otherwise (where N is @a l.size()). + */ + multiset(initializer_list<value_type> __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _M_t(__comp, __a) + { _M_t._M_insert_equal(__l.begin(), __l.end()); } #endif /** @@ -228,6 +245,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %Multiset list assignment operator. + * @param l An initializer_list. + * + * This function fills a %multiset with copies of the elements in the + * initializer list @a l. + * + * Note that the assignment completely changes the %multiset and + * that the resulting %multiset's size is the same as the number + * of elements assigned. Old data may be lost. + */ + multiset& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif // accessors: @@ -406,6 +442,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) insert(_InputIterator __first, _InputIterator __last) { _M_t._M_insert_equal(__first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Attempts to insert a list of elements into the %multiset. + * @param list A std::initializer_list<value_type> of elements + * to be inserted. + * + * Complexity similar to that of the range constructor. + */ + void + insert(initializer_list<value_type> __l) + { this->insert(__l.begin(), __l.end()); } +#endif + /** * @brief Erases an element from a %multiset. * @param position An iterator pointing to the element to be erased. diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 2ef51de..98c74e9 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -63,6 +63,7 @@ #define _STL_SET_H 1 #include <bits/concept_check.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -203,6 +204,22 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ set(set&& __x) : _M_t(std::forward<_Rep_type>(__x._M_t)) { } + + /** + * @brief Builds a %set from an initializer_list. + * @param l An initializer_list. + * @param comp A comparison functor. + * @param a An allocator object. + * + * Create a %set consisting of copies of the elements in the list. + * This is linear in N if the list is already sorted, and NlogN + * otherwise (where N is @a l.size()). + */ + set(initializer_list<value_type> __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _M_t(__comp, __a) + { _M_t._M_insert_unique(__l.begin(), __l.end()); } #endif /** @@ -235,6 +252,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %Set list assignment operator. + * @param l An initializer_list. + * + * This function fills a %set with copies of the elements in the + * initializer list @a l. + * + * Note that the assignment completely changes the %set and + * that the resulting %set's size is the same as the number + * of elements assigned. Old data may be lost. + */ + set& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif // accessors: @@ -418,6 +454,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) insert(_InputIterator __first, _InputIterator __last) { _M_t._M_insert_unique(__first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Attempts to insert a list of elements into the %set. + * @param list A std::initializer_list<value_type> of elements + * to be inserted. + * + * Complexity similar to that of the range constructor. + */ + void + insert(initializer_list<value_type> __l) + { this->insert(__l.begin(), __l.end()); } +#endif + /** * @brief Erases an element from a %set. * @param position An iterator pointing to the element to be erased. diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index aa874089..9ccd9b8 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -65,6 +65,7 @@ #include <bits/stl_iterator_base_funcs.h> #include <bits/functexcept.h> #include <bits/concept_check.h> +#include <initializer_list> _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) @@ -262,6 +263,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ vector(vector&& __x) : _Base(std::forward<_Base>(__x)) { } + + /** + * @brief Builds a %vector from an initializer list. + * @param l An initializer_list. + * @param a An allocator. + * + * Create a %vector consisting of copies of the elements in the + * initializer_list @a l. + * + * This will call the element type's copy constructor N times + * (where N is @a l.size()) and do no memory reallocation. + */ + vector(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + _M_range_initialize(__l.begin(), __l.end(), + random_access_iterator_tag()); + } #endif /** @@ -327,6 +347,24 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->swap(__x); return *this; } + + /** + * @brief %Vector list assignment operator. + * @param l An initializer_list. + * + * This function fills a %vector with copies of the elements in the + * initializer list @a l. + * + * Note that the assignment completely changes the %vector and + * that the resulting %vector's size is the same as the number + * of elements assigned. Old data may be lost. + */ + vector& + operator=(initializer_list<value_type> __l) + { + this->assign(__l.begin(), __l.end()); + return *this; + } #endif /** @@ -364,6 +402,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_assign_dispatch(__first, __last, _Integral()); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Assigns an initializer list to a %vector. + * @param l An initializer_list. + * + * This function fills a %vector with copies of the elements in the + * initializer list @a l. + * + * Note that the assignment completely changes the %vector and + * that the resulting %vector's size is the same as the number + * of elements assigned. Old data may be lost. + */ + void + assign(initializer_list<value_type> __l) + { this->assign(__l.begin(), __l.end()); } +#endif + /// Get a copy of the memory allocation object. using _Base::get_allocator; @@ -766,6 +821,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) iterator insert(iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } + + /** + * @brief Inserts an initializer_list into the %vector. + * @param position An iterator into the %vector. + * @param l An initializer_list. + * + * This function will insert copies of the data in the + * initializer_list @a l into the %vector before the location + * specified by @a position. + * + * Note that this kind of operation could be expensive for a + * %vector and if it is frequently used the user should + * consider using std::list. + */ + void + insert(iterator __position, initializer_list<value_type> __l) + { this->insert(__position, __l.begin(), __l.end()); } #endif /** diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index c37381f..845e0dc 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -94,6 +94,10 @@ namespace __debug deque(deque&& __x) : _Base(std::forward<deque>(__x)), _Safe_base() { this->_M_swap(__x); } + + deque(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a), _Safe_base() { } #endif ~deque() { } @@ -115,6 +119,14 @@ namespace __debug swap(__x); return *this; } + + deque& + operator=(initializer_list<value_type> __l) + { + *static_cast<_Base*>(this) = __l; + this->_M_invalidate_all(); + return *this; + } #endif template<class _InputIterator> @@ -133,6 +145,15 @@ namespace __debug this->_M_invalidate_all(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + assign(initializer_list<value_type> __l) + { + _Base::assign(__l); + this->_M_invalidate_all(); + } +#endif + using _Base::get_allocator; // iterators: @@ -318,6 +339,13 @@ namespace __debug iterator insert(iterator __position, _Tp&& __x) { return emplace(__position, std::move(__x)); } + + void + insert(iterator __p, initializer_list<value_type> __l) + { + _Base::insert(__p, __l); + this->_M_invalidate_all(); + } #endif void diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 7ab0bdd..312aeeb 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -123,6 +123,10 @@ namespace __debug list(list&& __x) : _Base(std::forward<list>(__x)), _Safe_base() { this->_M_swap(__x); } + + list(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a), _Safe_base() { } #endif ~list() { } @@ -144,6 +148,21 @@ namespace __debug swap(__x); return *this; } + + list& + operator=(initializer_list<value_type> __l) + { + static_cast<_Base&>(*this) = __l; + this->_M_invalidate_all(); + return *this; + } + + void + assign(initializer_list<value_type> __l) + { + _Base::assign(__l); + this->_M_invalidate_all(); + } #endif template<class _InputIterator> @@ -331,6 +350,13 @@ namespace __debug iterator insert(iterator __position, _Tp&& __x) { return emplace(__position, std::move(__x)); } + + void + insert(iterator __p, initializer_list<value_type> __l) + { + __glibcxx_check_insert(__p); + _Base::insert(__p, __l); + } #endif void diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h index 1657564..8232c74 100644 --- a/libstdc++-v3/include/debug/map.h +++ b/libstdc++-v3/include/debug/map.h @@ -98,6 +98,11 @@ namespace __debug map(map&& __x) : _Base(std::forward<map>(__x)), _Safe_base() { this->_M_swap(__x); } + + map(initializer_list<value_type> __l, + const _Compare& __c = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __c, __a), _Safe_base() { } #endif ~map() { } @@ -119,6 +124,14 @@ namespace __debug swap(__x); return *this; } + + map& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } #endif // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -198,6 +211,12 @@ namespace __debug __res.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(std::initializer_list<value_type> __list) + { _Base::insert(__list); } +#endif + iterator insert(iterator __position, const value_type& __x) { diff --git a/libstdc++-v3/include/debug/multimap.h b/libstdc++-v3/include/debug/multimap.h index 72f4411..b7c5ee7 100644 --- a/libstdc++-v3/include/debug/multimap.h +++ b/libstdc++-v3/include/debug/multimap.h @@ -99,6 +99,11 @@ namespace __debug multimap(multimap&& __x) : _Base(std::forward<multimap>(__x)), _Safe_base() { this->_M_swap(__x); } + + multimap(initializer_list<value_type> __l, + const _Compare& __c = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __c, __a), _Safe_base() { } #endif ~multimap() { } @@ -120,6 +125,14 @@ namespace __debug swap(__x); return *this; } + + multimap& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } #endif using _Base::get_allocator; @@ -185,6 +198,12 @@ namespace __debug insert(const value_type& __x) { return iterator(_Base::insert(__x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(std::initializer_list<value_type> __list) + { _Base::insert(__list); } +#endif + iterator insert(iterator __position, const value_type& __x) { diff --git a/libstdc++-v3/include/debug/multiset.h b/libstdc++-v3/include/debug/multiset.h index ffe5b51..f108531 100644 --- a/libstdc++-v3/include/debug/multiset.h +++ b/libstdc++-v3/include/debug/multiset.h @@ -96,6 +96,11 @@ namespace __debug multiset(multiset&& __x) : _Base(std::forward<multiset>(__x)), _Safe_base() { this->_M_swap(__x); } + + multiset(initializer_list<value_type> __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __comp, __a), _Safe_base() { } #endif ~multiset() { } @@ -117,6 +122,14 @@ namespace __debug swap(__x); return *this; } + + multiset& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } #endif using _Base::get_allocator; @@ -197,6 +210,12 @@ namespace __debug _Base::insert(__first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(initializer_list<value_type> __l) + { _Base::insert(__l); } +#endif + void erase(iterator __position) { diff --git a/libstdc++-v3/include/debug/safe_association.h b/libstdc++-v3/include/debug/safe_association.h index 42c0500..a413b01 100644 --- a/libstdc++-v3/include/debug/safe_association.h +++ b/libstdc++-v3/include/debug/safe_association.h @@ -105,6 +105,14 @@ namespace __gnu_debug __l, __n, __hf, __eql, __a) { } + _Safe_association(std::initializer_list<value_type> __l, + size_type __n, + const hasher& __hf, + const key_equal& __eql, + const allocator_type& __a = allocator_type()) + : _Base(__l, __n, __hf, __eql, __a) + { } + _Safe_association(const _Base& __x) : _Base(__x) { } _Safe_association(_Safe_association&& __x) @@ -152,6 +160,10 @@ namespace __gnu_debug _Base::insert(__first.base(), __last.base()); } + void + insert(std::initializer_list<value_type> __l) + { _Base::insert(__l); } + const_iterator find(const key_type& __key) const { return const_iterator(_Base::find(__key), this); } diff --git a/libstdc++-v3/include/debug/set.h b/libstdc++-v3/include/debug/set.h index 3115610..00711cd 100644 --- a/libstdc++-v3/include/debug/set.h +++ b/libstdc++-v3/include/debug/set.h @@ -96,6 +96,11 @@ namespace __debug set(set&& __x) : _Base(std::forward<set>(__x)), _Safe_base() { this->_M_swap(__x); } + + set(initializer_list<value_type> __l, + const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__l, __comp, __a), _Safe_base() { } #endif ~set() { } @@ -117,6 +122,14 @@ namespace __debug swap(__x); return *this; } + + set& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } #endif using _Base::get_allocator; @@ -202,6 +215,12 @@ namespace __debug _Base::insert(__first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(initializer_list<value_type> __l) + { _Base::insert(__l); } +#endif + void erase(iterator __position) { diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index 070ca1f..68882fe 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -115,6 +115,12 @@ namespace __gnu_debug : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) + : _Base(__l, __a) + { } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + ~basic_string() { } basic_string& @@ -142,6 +148,16 @@ namespace __gnu_debug return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + basic_string& + operator=(initializer_list<_CharT> __l) + { + *static_cast<_Base*>(this) = __l; + this->_M_invalidate_all(); + return *this; + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + // 21.3.2 iterators: iterator begin() @@ -259,6 +275,16 @@ namespace __gnu_debug return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + basic_string& + operator+=(initializer_list<_CharT> __l) + { + _M_base() += __l; + this->_M_invalidate_all(); + return *this; + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + basic_string& append(const basic_string& __str) { @@ -372,6 +398,16 @@ namespace __gnu_debug return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + basic_string& + assign(initializer_list<_CharT> __l) + { + _Base::assign(__l); + this->_M_invalidate_all(); + return *this; + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + basic_string& insert(size_type __pos1, const basic_string& __str) { @@ -441,6 +477,15 @@ namespace __gnu_debug this->_M_invalidate_all(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + insert(iterator __p, initializer_list<_CharT> __l) + { + _Base::insert(__p, __l); + this->_M_invalidate_all(); + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + basic_string& erase(size_type __pos = 0, size_type __n = _Base::npos) { @@ -564,6 +609,17 @@ namespace __gnu_debug return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + basic_string& replace(iterator __i1, iterator __i2, + initializer_list<_CharT> __l) + { + __glibcxx_check_erase_range(__i1, __i2); + _Base::replace(__i1.base(), __i2.base(), __l); + this->_M_invalidate_all(); + return *this; + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const { diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map index 590d4a3..79590f5 100644 --- a/libstdc++-v3/include/debug/unordered_map +++ b/libstdc++-v3/include/debug/unordered_map @@ -40,6 +40,7 @@ #else # include <c++0x_warning.h> #endif +#include <initializer_list> #include <debug/safe_association.h> #include <debug/safe_iterator.h> @@ -64,6 +65,7 @@ namespace __debug public: typedef typename _Safe_assoc::size_type size_type; + typedef typename _Safe_assoc::value_type value_type; typedef typename _Safe_assoc::hasher hasher; typedef typename _Safe_assoc::key_equal key_equal; typedef typename _Safe_assoc::allocator_type allocator_type; @@ -91,6 +93,13 @@ namespace __debug unordered_map(unordered_map&& __x) : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { } + unordered_map(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Safe_assoc(__l, __n, __hf, __eql, __a) { } + unordered_map& operator=(unordered_map&& __x) { @@ -100,6 +109,14 @@ namespace __debug return *this; } + unordered_map& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } + void swap(unordered_map&& __x) { @@ -164,6 +181,7 @@ namespace __debug public: typedef typename _Safe_assoc::size_type size_type; + typedef typename _Safe_assoc::value_type value_type; typedef typename _Safe_assoc::hasher hasher; typedef typename _Safe_assoc::key_equal key_equal; typedef typename _Safe_assoc::allocator_type allocator_type; @@ -185,6 +203,13 @@ namespace __debug : _Safe_assoc(__f, __l, __n, __hf, __eql, __a) { } + unordered_multimap(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Safe_assoc(__l, __n, __hf, __eql, __a) { } + unordered_multimap(const _Safe_assoc& __x) : _Safe_assoc(__x), _Safe_base() { } @@ -200,6 +225,14 @@ namespace __debug return *this; } + unordered_multimap& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } + void swap(unordered_multimap&& __x) { diff --git a/libstdc++-v3/include/debug/unordered_set b/libstdc++-v3/include/debug/unordered_set index b4b9be8..4c5d4d5 100644 --- a/libstdc++-v3/include/debug/unordered_set +++ b/libstdc++-v3/include/debug/unordered_set @@ -41,6 +41,7 @@ # include <c++0x_warning.h> #endif +#include <initializer_list> #include <debug/safe_association.h> #include <debug/safe_iterator.h> @@ -65,6 +66,7 @@ namespace __debug public: typedef typename _Safe_assoc::size_type size_type; + typedef typename _Safe_assoc::value_type value_type; typedef typename _Safe_assoc::hasher hasher; typedef typename _Safe_assoc::key_equal key_equal; typedef typename _Safe_assoc::allocator_type allocator_type; @@ -86,6 +88,13 @@ namespace __debug : _Safe_assoc(__f, __l, __n, __hf, __eql, __a) { } + unordered_set(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Safe_assoc(__l, __n, __hf, __eql, __a) { } + unordered_set(const _Safe_assoc& __x) : _Safe_assoc(__x), _Safe_base() { } @@ -101,6 +110,14 @@ namespace __debug return *this; } + unordered_set& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } + void swap(unordered_set&& __x) { @@ -162,6 +179,7 @@ namespace __debug public: typedef typename _Safe_assoc::size_type size_type; + typedef typename _Safe_assoc::value_type value_type; typedef typename _Safe_assoc::hasher hasher; typedef typename _Safe_assoc::key_equal key_equal; typedef typename _Safe_assoc::allocator_type allocator_type; @@ -183,6 +201,13 @@ namespace __debug : _Safe_assoc(__f, __l, __n, __hf, __eql, __a) { } + unordered_multiset(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Safe_assoc(__l, __n, __hf, __eql, __a) { } + unordered_multiset(const _Safe_assoc& __x) : _Safe_assoc(__x), _Safe_base() { } @@ -198,6 +223,14 @@ namespace __debug return *this; } + unordered_multiset& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l); + return *this; + } + void swap(unordered_multiset&& __x) { diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index f0c63a6..a004192 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -106,6 +106,11 @@ namespace __debug this->_M_swap(__x); __x._M_guaranteed_capacity = 0; } + + vector(initializer_list<value_type> __l, + const allocator_type& __a = allocator_type()) + : _Base(__l, __a), _Safe_base(), + _M_guaranteed_capacity(__l.size()) { } #endif ~vector() { } @@ -128,6 +133,15 @@ namespace __debug swap(__x); return *this; } + + vector& + operator=(initializer_list<value_type> __l) + { + static_cast<_Base&>(*this) = __l; + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + return *this; + } #endif template<typename _InputIterator> @@ -148,6 +162,16 @@ namespace __debug _M_update_guaranteed_capacity(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + assign(initializer_list<value_type> __l) + { + _Base::assign(__l); + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + } +#endif + using _Base::get_allocator; // iterators: @@ -367,6 +391,10 @@ namespace __debug iterator>::__type insert(iterator __position, _Tp&& __x) { return emplace(__position, std::move(__x)); } + + void + insert(iterator __position, initializer_list<value_type> __l) + { this->insert(__position, __l.begin(), __l.end()); } #endif void diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index 0d3224c..82c614c 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -308,7 +308,10 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #ifdef __GXX_EXPERIMENTAL_CXX0X__ __rc_string_base(__rc_string_base&& __rcs) : _M_dataplus(__rcs._M_get_allocator(), __rcs._M_data()) - { __rcs._M_data(_S_empty_rep._M_refcopy()); } + { __rcs._M_data(_S_empty_rep._M_refcopy()); } + + __rc_string_base(std::initializer_list<_CharT> __l, const _Alloc& __a) + : _M_dataplus(__a, _S_construct(__l.begin(), __l.end(), __a)) { } #endif __rc_string_base(size_type __n, _CharT __c, const _Alloc& __a); diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index 9c8c1bc..3335818 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -184,6 +184,10 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #ifdef __GXX_EXPERIMENTAL_CXX0X__ __sso_string_base(__sso_string_base&& __rcs); + + __sso_string_base(std::initializer_list<_CharT> __l, const _Alloc& __a) + : _M_dataplus(__a, _M_local_data) + { _M_construct(__l.begin(), __l.end()); } #endif __sso_string_base(size_type __n, _CharT __c, const _Alloc& __a); diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 0e74bfa..6002b19 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -36,6 +36,7 @@ #pragma GCC system_header +#include <initializer_list> #include <ext/vstring_util.h> #include <ext/rc_string_base.h> #include <ext/sso_string_base.h> @@ -156,6 +157,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) */ __versa_string(__versa_string&& __str) : __vstring_base(std::forward<__vstring_base>(__str)) { } + + /** + * @brief Construct string from an initializer list. + * @param l std::initializer_list of characters. + * @param a Allocator to use (default is default allocator). + */ + __versa_string(std::initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) + : __vstring_base(__l, __a) { } #endif /** @@ -257,6 +266,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) this->swap(__str); return *this; } + + /** + * @brief Set value to string constructed from initializer list. + * @param l std::initializer_list. + */ + __versa_string& + operator=(std::initializer_list<_CharT> __l) + { + this->assign (__l.begin(), __l.end()); + return *this; + } #endif /** @@ -623,6 +643,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Append an initializer_list of characters. + * @param l The initializer_list of characters to be appended. + * @return Reference to this string. + */ + __versa_string& + operator+=(std::initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Append a string to this string. * @param str The string to append. @@ -690,6 +721,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) append(size_type __n, _CharT __c) { return _M_replace_aux(this->size(), size_type(0), __n, __c); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Append an initializer_list of characters. + * @param l The initializer_list of characters to append. + * @return Reference to this string. + */ + __versa_string& + append(std::initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Append a range of characters. * @param first Iterator referencing the first character to append. @@ -807,6 +849,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) assign(_InputIterator __first, _InputIterator __last) { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Set value to an initializer_list of characters. + * @param l The initializer_list of characters to assign. + * @return Reference to this string. + */ + __versa_string& + assign(std::initializer_list<_CharT> __l) + { return this->assign(__l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Insert multiple characters. * @param p Iterator referencing location in string to insert at. @@ -839,6 +892,18 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) insert(iterator __p, _InputIterator __beg, _InputIterator __end) { this->replace(__p, __p, __beg, __end); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Insert an initializer_list of characters. + * @param p Iterator referencing location in string to insert at. + * @param l The initializer_list of characters to insert. + * @throw std::length_error If new length exceeds @c max_size(). + */ + void + insert(iterator __p, std::initializer_list<_CharT> __l) + { this->insert(__p, __l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + /** * @brief Insert value of a string. * @param pos1 Iterator referencing location in string to insert at. @@ -1295,6 +1360,25 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) __k1.base(), __k2 - __k1); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Replace range of characters with initializer_list. + * @param i1 Iterator referencing start of range to replace. + * @param i2 Iterator referencing end of range to replace. + * @param l The initializer_list of characters to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, characters + * in the range [k1,k2) are inserted. 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. + */ + __versa_string& replace(iterator __i1, iterator __i2, + std::initializer_list<_CharT> __l) + { return this->replace(__i1, __i2, __l.begin(), __l.end()); } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + private: template<class _Integer> __versa_string& diff --git a/libstdc++-v3/include/std/unordered_map b/libstdc++-v3/include/std/unordered_map index e338ef7..2b7d328 100644 --- a/libstdc++-v3/include/std/unordered_map +++ b/libstdc++-v3/include/std/unordered_map @@ -46,6 +46,7 @@ #include <utility> #include <type_traits> +#include <initializer_list> #include <bits/stl_algobase.h> #include <bits/allocator.h> #include <bits/stl_function.h> // equal_to, _Identity, _Select1st diff --git a/libstdc++-v3/include/std/unordered_set b/libstdc++-v3/include/std/unordered_set index 13b412b..1cabae9 100644 --- a/libstdc++-v3/include/std/unordered_set +++ b/libstdc++-v3/include/std/unordered_set @@ -46,6 +46,7 @@ #include <utility> #include <type_traits> +#include <initializer_list> #include <bits/stl_algobase.h> #include <bits/allocator.h> #include <bits/stl_function.h> // equal_to, _Identity, _Select1st diff --git a/libstdc++-v3/include/std/valarray b/libstdc++-v3/include/std/valarray index 31799c0..b0fa512 100644 --- a/libstdc++-v3/include/std/valarray +++ b/libstdc++-v3/include/std/valarray @@ -45,6 +45,7 @@ #include <cmath> #include <algorithm> #include <debug/debug.h> +#include <initializer_list> _GLIBCXX_BEGIN_NAMESPACE(std) @@ -144,6 +145,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) /// Construct an array with the same size and values in @a ia. valarray(const indirect_array<_Tp>&); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /// Construct an array with an initializer_list of values. + valarray(initializer_list<_Tp>); +#endif + template<class _Dom> valarray(const _Expr<_Dom, _Tp>& __e); @@ -209,6 +215,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std) */ valarray<_Tp>& operator=(const indirect_array<_Tp>&); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Assign elements to an initializer_list. + * + * Assign elements of array to values in @a l. Results are undefined + * if @a l does not have the same size as this array. + * + * @param l initializer_list to get values from. + */ + valarray& operator=(initializer_list<_Tp>); +#endif + template<class _Dom> valarray<_Tp>& operator= (const _Expr<_Dom, _Tp>&); @@ -615,6 +633,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp> + inline + valarray<_Tp>::valarray(initializer_list<_Tp> __l) + : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size())) + { std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); } +#endif + template<typename _Tp> template<class _Dom> inline valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e) @@ -638,6 +664,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp> + inline valarray<_Tp>& + valarray<_Tp>::operator=(initializer_list<_Tp> __l) + { + _GLIBCXX_DEBUG_ASSERT(_M_size == __l.size()); + std::__valarray_copy(__l.begin(), __l.size(), _M_data); + } +#endif + template<typename _Tp> inline valarray<_Tp>& valarray<_Tp>::operator=(const _Tp& __t) diff --git a/libstdc++-v3/include/tr1_impl/hashtable b/libstdc++-v3/include/tr1_impl/hashtable index 55056ef..33857a4 100644 --- a/libstdc++-v3/include/tr1_impl/hashtable +++ b/libstdc++-v3/include/tr1_impl/hashtable @@ -434,6 +434,12 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 void insert(_InputIterator __first, _InputIterator __last); +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + void + insert(initializer_list<value_type> __l) + { this->insert(__l.begin(), __l.end()); } +#endif + iterator erase(iterator); diff --git a/libstdc++-v3/include/tr1_impl/regex b/libstdc++-v3/include/tr1_impl/regex index f99e006..d5e80b1 100644 --- a/libstdc++-v3/include/tr1_impl/regex +++ b/libstdc++-v3/include/tr1_impl/regex @@ -730,6 +730,13 @@ namespace regex_constants : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0) { _M_compile(); } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + basic_regex(initializer_list<_Ch_type> __l, + flag_type __f = regex_constants::ECMAScript) + : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0) + { _M_compile(); } +#endif + /** * @brief Destroys a basic regular expression. */ @@ -854,6 +861,13 @@ namespace regex_constants flag_type __flags = regex_constants::ECMAScript) { return this->assign(string_type(__first, __last), __flags); } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + basic_regex& + assign(initializer_list<_Ch_type> __l, + flag_type __f = regex_constants::ECMAScript) + { return this->assign(__l.begin(), __l.end(), __f); } +#endif + // [7.8.4] const operations /** * @brief Gets the number of marked subexpressions within the regular diff --git a/libstdc++-v3/include/tr1_impl/unordered_map b/libstdc++-v3/include/tr1_impl/unordered_map index bb69479..4f91449 100644 --- a/libstdc++-v3/include/tr1_impl/unordered_map +++ b/libstdc++-v3/include/tr1_impl/unordered_map @@ -179,6 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 typedef __unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -205,6 +206,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 unordered_map(unordered_map&& __x) : _Base(std::forward<_Base>(__x)) { } + unordered_map(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + { } + unordered_map& operator=(unordered_map&& __x) { @@ -213,6 +222,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 this->swap(__x); return *this; } + + unordered_map& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif }; @@ -227,6 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 typedef __unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -254,6 +272,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 unordered_multimap(unordered_multimap&& __x) : _Base(std::forward<_Base>(__x)) { } + unordered_multimap(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + { } + unordered_multimap& operator=(unordered_multimap&& __x) { @@ -262,6 +288,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 this->swap(__x); return *this; } + + unordered_multimap& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif }; diff --git a/libstdc++-v3/include/tr1_impl/unordered_set b/libstdc++-v3/include/tr1_impl/unordered_set index 80b1ec5..5640ebe 100644 --- a/libstdc++-v3/include/tr1_impl/unordered_set +++ b/libstdc++-v3/include/tr1_impl/unordered_set @@ -175,6 +175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 typedef __unordered_set<_Value, _Hash, _Pred, _Alloc> _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -201,6 +202,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 unordered_set(unordered_set&& __x) : _Base(std::forward<_Base>(__x)) { } + unordered_set(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + { } + unordered_set& operator=(unordered_set&& __x) { @@ -209,6 +218,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 this->swap(__x); return *this; } + + unordered_set& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif }; @@ -223,6 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc> _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -250,6 +268,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 unordered_multiset(unordered_multiset&& __x) : _Base(std::forward<_Base>(__x)) { } + unordered_multiset(initializer_list<value_type> __l, + size_type __n = 10, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + { } + unordered_multiset& operator=(unordered_multiset&& __x) { @@ -258,6 +284,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 this->swap(__x); return *this; } + + unordered_multiset& + operator=(initializer_list<value_type> __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } #endif }; |