diff options
Diffstat (limited to 'libstdc++-v3/include/bits')
| -rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 87 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 8 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_bvector.h | 28 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_deque.h | 68 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_list.h | 58 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_map.h | 37 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_multimap.h | 49 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_multiset.h | 49 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_set.h | 49 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 72 |
10 files changed, 504 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 19c79d11cf7..de4cf80234d 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 49b649446d3..3201e361830 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 045f20378a6..ad0ed87a115 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 b778f15a075..070fc078909 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 08fb89ef117..b38fa55cf79 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 cd85b9ab75d..b402b8292c5 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 ade2750170f..0834c95cfd6 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 2cdbdfe4cf3..2fea83f847c 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 2ef51de858f..98c74e9a27c 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 aa874089d52..9ccd9b8ca23 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 /** |

