mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Add std::initializer_list to the following containers:
* deque * map * multimap * set * multiset * list * slist Tested on clant and g++
This commit is contained in:
@@ -42,6 +42,10 @@
|
||||
#include <boost/container/detail/advanced_insert_int.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
@@ -603,6 +607,21 @@ class deque : protected deque_base<Allocator>
|
||||
this->priv_range_initialize(first, last, ItCat());
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
|
||||
//! and inserts a copy of the range [il.begin(), il.end()) in the deque.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator_type's default constructor
|
||||
//! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
|
||||
deque(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
|
||||
: Base(a)
|
||||
{
|
||||
this->priv_range_initialize(il.begin(), il.end(), std::input_iterator_tag());
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Copy constructs a deque.
|
||||
//!
|
||||
//! <b>Postcondition</b>: x == *this.
|
||||
@@ -741,6 +760,22 @@ class deque : protected deque_base<Allocator>
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Makes *this contain the same elements as il.
|
||||
//!
|
||||
//! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
|
||||
//! of each of x's elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the number of elements in il.
|
||||
deque& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
this->assign(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Assigns the n copies of val to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
@@ -802,6 +837,17 @@ class deque : protected deque_base<Allocator>
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or
|
||||
//! T's constructor from dereferencing std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to il.size().
|
||||
void assign(std::initializer_list<value_type> il)
|
||||
{ this->assign(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Returns a copy of the internal allocator.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator's copy constructor throws.
|
||||
@@ -1389,6 +1435,21 @@ class deque : protected deque_base<Allocator>
|
||||
return it;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Requires</b>: pos must be a valid iterator of *this.
|
||||
//!
|
||||
//! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before pos.
|
||||
//!
|
||||
//! <b>Returns</b>: an iterator to the first inserted element or pos if il.begin() == il.end().
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws, T's constructor from a
|
||||
//! dereferenced std::initializer_list throws or T's copy constructor throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to std::distance [il.begin(), il.end()).
|
||||
iterator insert(const_iterator pos, std::initializer_list<value_type> il)
|
||||
{ return insert(pos, il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
template <class FwdIt>
|
||||
iterator insert(const_iterator p, FwdIt first, FwdIt last
|
||||
|
@@ -38,6 +38,10 @@
|
||||
#include <boost/container/detail/preprocessor.hpp>
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
@@ -299,6 +303,21 @@ class list
|
||||
: AllocHolder(a)
|
||||
{ this->insert(this->cbegin(), first, last); }
|
||||
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs a list that will use a copy of allocator a
|
||||
//! and inserts a copy of the range [il.begin(), il.end()) in the list.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator_type's default constructor
|
||||
//! throws or T's constructor taking a dereferenced
|
||||
//! std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
|
||||
list(std::initializer_list<value_type> il, const Allocator &a = Allocator())
|
||||
: AllocHolder(a)
|
||||
{ this->insert(this->cbegin(), il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Destroys the list. All stored values are destroyed
|
||||
//! and used memory is deallocated.
|
||||
//!
|
||||
@@ -370,6 +389,22 @@ class list
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Makes *this contain the same elements as il.
|
||||
//!
|
||||
//! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
|
||||
//! of each of x's elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the number of elements in x.
|
||||
list& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
assign(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Assigns the n copies of val to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
@@ -407,6 +442,17 @@ class list
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or
|
||||
//! T's constructor from dereferencing std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to n.
|
||||
void assign(std::initializer_list<value_type> il)
|
||||
{ assign(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Returns a copy of the internal allocator.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator's copy constructor throws.
|
||||
@@ -860,6 +906,21 @@ class list
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Requires</b>: p must be a valid iterator of *this.
|
||||
//!
|
||||
//! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
|
||||
//!
|
||||
//! <b>Returns</b>: an iterator to the first inserted element or p if if.begin() == il.end().
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws, T's constructor from a
|
||||
//! dereferenced std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to std::distance [il.begin(), il.end()).
|
||||
iterator insert(const_iterator p, std::initializer_list<value_type> il)
|
||||
{ return insert(p, il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Removes the first element from the list.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
|
@@ -36,6 +36,10 @@
|
||||
#include <boost/container/detail/value_init.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
@@ -180,6 +184,28 @@ class map
|
||||
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs an empty map using the specified comparison object and
|
||||
//! allocator, and inserts elements from the range [il.begin(), il.end()).
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
|
||||
//! comp and otherwise N logN, where N is il.first() - il.end().
|
||||
map(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
|
||||
: base_t(true, il.begin(), il.end(), comp, a)
|
||||
{
|
||||
//Allocator type must be std::pair<CONST Key, T>
|
||||
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
|
||||
}
|
||||
|
||||
map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
|
||||
const allocator_type& a = allocator_type())
|
||||
: base_t(ordered_range, il.begin(), il.end(), comp, a)
|
||||
{
|
||||
//Allocator type must be std::pair<CONST Key, T>
|
||||
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Copy constructs a map.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in x.size().
|
||||
@@ -243,6 +269,17 @@ class map
|
||||
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
|
||||
{ return static_cast<map&>(this->base_t::operator=(boost::move(static_cast<base_t&>(x)))); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Assign content of il to *this.
|
||||
//!
|
||||
map& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
this->clear();
|
||||
insert(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! <b>Effects</b>: Returns a copy of the Allocator that
|
||||
@@ -551,6 +588,15 @@ class map
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{ this->base_t::insert_unique(first, last); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
|
||||
//! if there is no element with key equivalent to the key of that element.
|
||||
//!
|
||||
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
|
||||
void insert(std::initializer_list<value_type> il)
|
||||
{ this->base_t::insert_unique(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! <b>Effects</b>: Inserts an object x of type T constructed with
|
||||
@@ -935,6 +981,29 @@ class multimap
|
||||
: base_t(ordered_range, first, last, comp, a)
|
||||
{}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
|
||||
//! allocator, and inserts elements from the range [il.begin(), il.end()).
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
|
||||
//! comp and otherwise N logN, where N is il.first() - il.end().
|
||||
multimap(std::initializer_list<value_type> il, const Compare& comp = Compare(),
|
||||
const allocator_type& a = allocator_type())
|
||||
: base_t(false, il.begin(), il.end(), comp, a)
|
||||
{
|
||||
//Allocator type must be std::pair<CONST Key, T>
|
||||
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
|
||||
}
|
||||
|
||||
multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
|
||||
const allocator_type& a = allocator_type())
|
||||
: base_t(ordered_range, il.begin(), il.end(), comp, a)
|
||||
{
|
||||
//Allocator type must be std::pair<CONST Key, T>
|
||||
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Copy constructs a multimap.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in x.size().
|
||||
@@ -991,6 +1060,17 @@ class multimap
|
||||
multimap& operator=(BOOST_RV_REF(multimap) x)
|
||||
{ return static_cast<multimap&>(this->base_t::operator=(boost::move(static_cast<base_t&>(x)))); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Assign content of il to *this.
|
||||
//!
|
||||
multimap& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
this->clear();
|
||||
insert(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! @copydoc ::boost::container::set::get_allocator()
|
||||
@@ -1176,6 +1256,14 @@ class multimap
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{ this->base_t::insert_equal(first, last); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: inserts each element from the range [il.begin(), il.end().
|
||||
//!
|
||||
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
|
||||
void insert(std::initializer_list<value_type> il)
|
||||
{ this->base_t::insert_equal(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! @copydoc ::boost::container::set::erase(const_iterator)
|
||||
|
@@ -31,6 +31,9 @@
|
||||
#ifndef BOOST_CONTAINER_PERFECT_FORWARDING
|
||||
#include <boost/container/detail/preprocessor.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
@@ -146,6 +149,31 @@ class set
|
||||
: base_t(ordered_range, first, last, comp, a)
|
||||
{}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs an empty set using the specified comparison object and
|
||||
//! allocator, and inserts elements from the range [il.begin(), il.end()).
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in N if the range [il.begin(), il.end()) is already sorted using
|
||||
//! comp and otherwise N logN, where N is il.begin() - il.end().
|
||||
set(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
|
||||
: base_t(true, il.begin(), il.end(), comp, a)
|
||||
{}
|
||||
|
||||
//! <b>Effects</b>: Constructs an empty set using the specified comparison object and
|
||||
//! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
|
||||
//! is more efficient than the normal range creation for ordered ranges.
|
||||
//!
|
||||
//! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
|
||||
//! unique values.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in N.
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
set(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
|
||||
: base_t(ordered_range, il.begin(), il.end(), comp, a)
|
||||
{}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Copy constructs a set.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear in x.size().
|
||||
@@ -195,6 +223,15 @@ class set
|
||||
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
|
||||
{ return static_cast<set&>(this->base_t::operator=(boost::move(static_cast<base_t&>(x)))); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
set& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
this->clear();
|
||||
insert(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! <b>Effects</b>: Returns a copy of the Allocator that
|
||||
@@ -444,6 +481,15 @@ class set
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{ this->base_t::insert_unique(first, last); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: inserts each element from the range [il.begin(),il.end()) if and only
|
||||
//! if there is no element with key equivalent to the key of that element.
|
||||
//!
|
||||
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
|
||||
void insert(std::initializer_list<value_type> il)
|
||||
{ this->base_t::insert_unique(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! <b>Effects</b>: Erases the element pointed to by p.
|
||||
@@ -745,6 +791,19 @@ class multiset
|
||||
: base_t(ordered_range, first, last, comp, a)
|
||||
{}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! @copydoc ::boost::container::set::set(std::initializer_list<value_type>, const Compare& comp, const allocator_type&)
|
||||
multiset(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
|
||||
: base_t(false, il.begin(), il.end(), comp, a)
|
||||
{}
|
||||
|
||||
//! @copydoc ::boost::container::set::set(ordered_unique_range_t, std::initializer_list<value_type>, const Compare& comp, const allocator_type&)
|
||||
multiset(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
|
||||
: base_t(ordered_range, il.begin(), il.end(), comp, a)
|
||||
{}
|
||||
#endif
|
||||
|
||||
|
||||
//! @copydoc ::boost::container::set::set(const set &)
|
||||
multiset(const multiset& x)
|
||||
: base_t(static_cast<const base_t&>(x))
|
||||
@@ -773,6 +832,15 @@ class multiset
|
||||
multiset& operator=(BOOST_RV_REF(multiset) x)
|
||||
{ return static_cast<multiset&>(this->base_t::operator=(boost::move(static_cast<base_t&>(x)))); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! @copydoc ::boost::container::set::operator=(std::initializer_list<value_type>)
|
||||
multiset& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
this->clear();
|
||||
insert(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! @copydoc ::boost::container::set::get_allocator()
|
||||
@@ -924,6 +992,12 @@ class multiset
|
||||
void insert(InputIterator first, InputIterator last)
|
||||
{ this->base_t::insert_equal(first, last); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! @copydoc ::boost::container::set::insert(std::initializer_list<value_type>)
|
||||
void insert(std::initializer_list<value_type> il)
|
||||
{ this->base_t::insert_unique(il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! @copydoc ::boost::container::set::erase(const_iterator)
|
||||
|
@@ -45,6 +45,11 @@
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
@@ -272,6 +277,19 @@ class slist
|
||||
: AllocHolder(a)
|
||||
{ this->insert_after(this->cbefore_begin(), first, last); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Constructs a list that will use a copy of allocator a
|
||||
//! and inserts a copy of the range [il.begin(), il.end()) in the list.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator_type's default constructor
|
||||
//! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
|
||||
slist(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
|
||||
: AllocHolder(a)
|
||||
{ this->insert_after(this->cbefore_begin(), il.begin(), il.end()); }
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Copy constructs a list.
|
||||
//!
|
||||
//! <b>Postcondition</b>: x == *this.
|
||||
@@ -391,6 +409,21 @@ class slist
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Makes *this contain the same elements as in il.
|
||||
//!
|
||||
//! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
|
||||
//! of each of il's elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
|
||||
//! is false and (allocation throws or value_type's move constructor throws)
|
||||
slist& operator=(std::initializer_list<value_type> il)
|
||||
{
|
||||
assign(il.begin(), il.end());
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Assigns the n copies of val to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
@@ -432,6 +465,19 @@ class slist
|
||||
this->erase_after(prev, end_n);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or
|
||||
//! T's constructor from dereferencing std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to range [il.begin(), il.end()).
|
||||
|
||||
void assign(std::initializer_list<value_type> il)
|
||||
{
|
||||
assign(il.begin(), il.end());
|
||||
}
|
||||
#endif
|
||||
//! <b>Effects</b>: Returns a copy of the internal allocator.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator's copy constructor throws.
|
||||
@@ -817,6 +863,25 @@ class slist
|
||||
return ret_it;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Requires</b>: prev_p must be a valid iterator of *this.
|
||||
//!
|
||||
//! <b>Effects</b>: Inserts the range pointed by [il.begin(), il.end()) after prev_p.
|
||||
//!
|
||||
//! <b>Returns</b>: an iterator to the last inserted element or prev_p if il.begin() == il.end().
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws, T's constructor from a
|
||||
//! dereferenced std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the number of elements inserted.
|
||||
//!
|
||||
//! <b>Note</b>: Does not affect the validity of iterators and references of
|
||||
//! previous values.
|
||||
iterator insert_after(const_iterator prev_p, std::initializer_list<value_type> il)
|
||||
{
|
||||
return insert_after(prev_p, il.begin(), il.end());
|
||||
}
|
||||
#endif
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
template <class FwdIt>
|
||||
iterator insert_after(const_iterator prev, FwdIt first, FwdIt last
|
||||
@@ -1313,6 +1378,24 @@ class slist
|
||||
return ++iterator(prev.get());
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
//! <b>Requires</b>: p must be a valid iterator of *this.
|
||||
//!
|
||||
//! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
|
||||
//!
|
||||
//! <b>Returns</b>: an iterator to the first inserted element or p if il.begin() == il.end().
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws, T's constructor from a
|
||||
//! dereferenced std::initializer_list iterator throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the range [il.begin(), il.end()) plus
|
||||
//! linear to the elements before p.
|
||||
iterator insert(const_iterator p, std::initializer_list<value_type> il)
|
||||
{
|
||||
return insert(p, il.begin(), il.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//! <b>Requires</b>: p must be a valid iterator of *this.
|
||||
//!
|
||||
//! <b>Effects</b>: Erases the element at p p.
|
||||
|
@@ -341,6 +341,36 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initialization_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {1, 10, 11};
|
||||
const deque<int> expectedDeque(il.begin(), il.end());
|
||||
|
||||
const deque<int> testConstructor = il;
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testAssignmentOperator = {11, 12, 23};
|
||||
testAssignmentOperator = il;
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testAssignmentMethod = {11, 12, 23};
|
||||
testAssignmentMethod.assign(il);
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
deque<int> testInsertMethod = {11};
|
||||
testInsertMethod.insert(testInsertMethod.cbegin(), {12, 23});
|
||||
if(testConstructor != expectedDeque)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -396,6 +426,9 @@ int main ()
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_support_for_initialization_list())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Emplace testing
|
||||
////////////////////////////////////
|
||||
|
@@ -115,6 +115,35 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initializer_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {1, 10};
|
||||
const list<int> expectedList(il.begin(), il.end());
|
||||
|
||||
const list<int> testConstructor = il;
|
||||
if(testConstructor != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testAssignOperator = {10, 11};
|
||||
testAssignOperator = il;
|
||||
if(testAssignOperator != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testAssignMethod = {99};
|
||||
testAssignMethod = il;
|
||||
if(testAssignMethod != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testInsertMethod;
|
||||
testInsertMethod.insert(testInsertMethod.cbegin(), il);
|
||||
if(testInsertMethod != testInsertMethod)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -166,6 +195,9 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<list>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initializer_list())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <boost/container/allocator.hpp>
|
||||
#include <boost/container/node_allocator.hpp>
|
||||
#include <boost/container/adaptive_pool.hpp>
|
||||
#include <utility>
|
||||
|
||||
#include "print_container.hpp"
|
||||
#include "movable_int.hpp"
|
||||
@@ -345,6 +346,38 @@ int test_map_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename MapType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<const int, int>> il
|
||||
= {std::make_pair(1, 2), std::make_pair(3, 4)};
|
||||
const MapType expected(il.begin(), il.end());
|
||||
{
|
||||
const MapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
const MapType sil_ordered(ordered_unique_range_t{}, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
MapType sil_assign = {std::make_pair(99, 100)};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
MapType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
//Recursive container instantiation
|
||||
@@ -421,6 +454,12 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<map_propagate_test_wrapper>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<map<int, int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multimap<int, int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Test optimize_size option
|
||||
////////////////////////////////////
|
||||
|
@@ -314,7 +314,36 @@ int test_set_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename SetType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
std::initializer_list<int> il = {1, 2, 3, 4, 5};
|
||||
SetType expected(il.begin(), il.end());
|
||||
{
|
||||
SetType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_ordered(ordered_unique_range_t{}, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_assign = {99, 100, 101, 102, 103, 104, 105};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
SetType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
//Recursive container instantiation
|
||||
@@ -391,6 +420,12 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<set_propagate_test_wrapper>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<set<int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multiset<int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Test optimize_size option
|
||||
////////////////////////////////////
|
||||
|
@@ -101,6 +101,48 @@ int test_cont_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_support_for_initializer_list()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<int> il = {5, 10, 15};
|
||||
const slist<int> expected_list(il.begin(), il.end());
|
||||
{
|
||||
slist<int> sl = il;
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {1, 2};
|
||||
sl = il;
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {4, 5};
|
||||
sl.assign(il);
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {15};
|
||||
sl.insert(sl.cbegin(), {5, 10});
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl = {5};
|
||||
sl.insert_after(sl.cbegin(), {10, 15});
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
@@ -159,6 +201,9 @@ int main ()
|
||||
////////////////////////////////////
|
||||
if(!boost::container::test::test_propagate_allocator<slist>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initializer_list())
|
||||
return 1;
|
||||
}
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
Reference in New Issue
Block a user