slist.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,612 行 · 第 1/4 页

HPP
1,612
字号
   //!   //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to the number of elements in x.   slist& operator= (const slist& x)   {      if (&x != this){         this->assign(x.begin(), x.end());      }      return *this;   }   //! <b>Effects</b>: Makes *this contain the same elements as x.   //!   //! <b>Postcondition</b>: this->size() == x.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.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   slist& operator= (const detail::moved_object<slist>& mx)   {      if (&mx.get() != this){         this->clear();         this->swap(mx.get());      }      return *this;   }   #else   slist& operator= (slist && mx)   {      if (&mx != this){         this->clear();         this->swap(mx);      }      return *this;   }   #endif   //! <b>Effects</b>: Destroys the list. All stored values are destroyed   //!   and used memory is deallocated.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Linear to the number of elements.   ~slist()    {  this->clear(); }   //! <b>Effects</b>: Returns a copy of the internal allocator.   //!    //! <b>Throws</b>: If allocator's copy constructor throws.   //!    //! <b>Complexity</b>: Constant.   allocator_type get_allocator() const   {  return allocator_type(this->node_alloc()); }   const stored_allocator_type &get_stored_allocator() const    {  return this->node_alloc(); }   stored_allocator_type &get_stored_allocator()   {  return this->node_alloc(); }   public:   //! <b>Effects</b>: Assigns the n copies of val to *this.   //!   //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to n.   void assign(size_type n, const T& val)   { this->priv_fill_assign(n, val); }   //! <b>Effects</b>: Assigns the range [first, last) to *this.   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's constructor from dereferencing InpIt throws.   //!   //! <b>Complexity</b>: Linear to n.   template <class InpIt>   void assign(InpIt first, InpIt last)    {      const bool aux_boolean = detail::is_convertible<InpIt, std::size_t>::value;      typedef detail::bool_<aux_boolean> Result;      this->priv_assign_dispatch(first, last, Result());   }   //! <b>Effects</b>: Returns an iterator to the first element contained in the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   iterator begin()    { return iterator(this->icont().begin()); }   //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator begin() const    {  return this->cbegin();   }   //! <b>Effects</b>: Returns an iterator to the end of the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   iterator end()   { return iterator(this->icont().end()); }   //! <b>Effects</b>: Returns a const_iterator to the end of the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator end() const   {  return this->cend();   }   //! <b>Effects</b>: Returns a non-dereferenceable iterator that,   //! when incremented, yields begin().  This iterator may be used   //! as the argument toinsert_after, erase_after, etc.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   iterator before_begin()    {  return iterator(end());  }   //! <b>Effects</b>: Returns a non-dereferenceable const_iterator    //! that, when incremented, yields begin().  This iterator may be used   //! as the argument toinsert_after, erase_after, etc.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator before_begin() const   {  return this->cbefore_begin();  }   //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator cbegin() const    {  return const_iterator(this->non_const_icont().begin());   }   //! <b>Effects</b>: Returns a const_iterator to the end of the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator cend() const   {  return const_iterator(this->non_const_icont().end());   }   //! <b>Effects</b>: Returns a non-dereferenceable const_iterator    //! that, when incremented, yields begin().  This iterator may be used   //! as the argument toinsert_after, erase_after, etc.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator cbefore_begin() const   {  return const_iterator(end());  }   //! <b>Effects</b>: Returns the number of the elements contained in the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   size_type size() const    {  return this->icont().size(); }   //! <b>Effects</b>: Returns the largest possible size of the list.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   size_type max_size() const    {  return AllocHolder::max_size();  }   //! <b>Effects</b>: Returns true if the list contains no elements.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   bool empty() const    {  return !this->size();   }   //! <b>Effects</b>: Swaps the contents of *this and x.   //!   If this->allocator_type() != x.allocator_type()   //!   allocators are also swapped.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Linear to the number of elements on *this and x.   void swap(slist& x)   {  AllocHolder::swap(x);   }   //! <b>Requires</b>: !empty()   //!   //! <b>Effects</b>: Returns a reference to the first element    //!   from the beginning of the container.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   reference front()    {  return *this->begin();  }   //! <b>Requires</b>: !empty()   //!   //! <b>Effects</b>: Returns a const reference to the first element    //!   from the beginning of the container.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reference front() const    {  return *this->begin();  }   //! <b>Effects</b>: Inserts a copy of t in the beginning of the list.   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's copy constructor throws.   //!   //! <b>Complexity</b>: Amortized constant time.   void push_front(const value_type& x)   {  this->icont().push_front(*this->create_node(x));  }   //! <b>Effects</b>: Constructs a new element in the beginning of the list   //!   and moves the resources of t to this new element.   //!   //! <b>Throws</b>: If memory allocation throws.   //!   //! <b>Complexity</b>: Amortized constant time.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   void push_front(const detail::moved_object<T>& x)   {  this->icont().push_front(*this->create_node(x));  }   #else   void push_front(T && x)   {  this->icont().push_front(*this->create_node(detail::move_impl(x)));  }   #endif   //! <b>Effects</b>: Removes the first element from the list.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Amortized constant time.   void pop_front()   {  this->icont().pop_front_and_dispose(Destroyer(this->node_alloc()));      }   //! <b>Returns</b>: The iterator to the element before i in the sequence.    //!   Returns the end-iterator, if either i is the begin-iterator or the    //!   sequence is empty.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Linear to the number of elements before i.    iterator previous(iterator p)    {  return iterator(this->icont().previous(p.get())); }   //! <b>Returns</b>: The const_iterator to the element before i in the sequence.    //!   Returns the end-const_iterator, if either i is the begin-const_iterator or    //!   the sequence is empty.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Linear to the number of elements before i.    const_iterator previous(const_iterator p)    {  return const_iterator(this->icont().previous(p.get())); }   //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Inserts a copy of the value after the p pointed   //!    by prev_p.   //!   //! <b>Returns</b>: An iterator to the inserted element.   //!    //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.   //!    //! <b>Complexity</b>: Amortized constant time.   //!   //! <b>Note</b>: Does not affect the validity of iterators and references of   //!   previous values.   iterator insert_after(const_iterator prev_pos, const value_type& x)    {  return iterator(this->icont().insert_after(prev_pos.get(), *this->create_node(x))); }   //! <b>Requires</b>: prev_pos must be a valid iterator of *this.   //!   //! <b>Effects</b>: Inserts a move constructed copy object from the value after the   //!    p pointed by prev_pos.   //!   //! <b>Returns</b>: An iterator to the inserted element.   //!    //! <b>Throws</b>: If memory allocation throws.   //!    //! <b>Complexity</b>: Amortized constant time.   //!   //! <b>Note</b>: Does not affect the validity of iterators and references of   //!   previous values.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   iterator insert_after(const_iterator prev_pos, const detail::moved_object<value_type>& x)    {  return iterator(this->icont().insert_after(prev_pos.get(), *this->create_node(x))); }   #else   iterator insert_after(const_iterator prev_pos, value_type && x)    {  return iterator(this->icont().insert_after(prev_pos.get(), *this->create_node(detail::move_impl(x)))); }   #endif   //! <b>Requires</b>: prev_pos must be a valid iterator of *this.   //!   //! <b>Effects</b>: Inserts n copies of x after prev_pos.   //!   //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to n.   //!   //! <b>Note</b>: Does not affect the validity of iterators and references of   //!   previous values.   void insert_after(const_iterator prev_pos, size_type n, const value_type& x)   {  this->priv_create_and_insert_nodes(prev_pos, n, x); }   //! <b>Requires</b>: prev_pos must be a valid iterator of *this.   //!    //! <b>Effects</b>: Inserts the range pointed by [first, last)    //!   after the p prev_pos.   //!    //! <b>Throws</b>: If memory allocation throws, T's constructor from a   //!   dereferenced InpIt 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.   template <class InIter>   void insert_after(const_iterator prev_pos, InIter first, InIter last)    {      const bool aux_boolean = detail::is_convertible<InIter, std::size_t>::value;      typedef detail::bool_<aux_boolean> Result;      this->priv_insert_after_range_dispatch(prev_pos, first, last, Result());   }   //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Insert a copy of x before p.   //!   //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to the elements before p.   iterator insert(const_iterator p, const value_type& x)    {  return this->insert_after(previous(p), x); }   //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Insert a new element before p with mx's resources.   //!   //! <b>Throws</b>: If memory allocation throws.   //!   //! <b>Complexity</b>: Linear to the elements before p.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   iterator insert(const_iterator p, const detail::moved_object<value_type>& x)    {  return this->insert_after(previous(p), x); }   #else   iterator insert(const_iterator p, value_type && x)    {  return this->insert_after(previous(p), detail::move_impl(x)); }   #endif   //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Inserts n copies of x before p.   //!   //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to n plus linear to the elements before p.   void insert(const_iterator p, size_type n, const value_type& x)    {  return this->insert_after(previous(p), n, x); }         //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Insert a copy of the [first, last) range before p.   //!   //! <b>Throws</b>: If memory allocation throws, T's constructor from a   //!   dereferenced InpIt throws.   //!   //! <b>Complexity</b>: Linear to std::distance [first, last) plus   //!    linear to the elements before p.   template <class InIter>   void insert(const_iterator p, InIter first, InIter last)    {  return this->insert_after(previous(p), first, last); }   #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING   //! <b>Effects</b>: Inserts an object of type T constructed with   //!   std::forward<Args>(args)... in the front of the list   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's copy constructor throws.   //!   //! <b>Complexity</b>: Amortized constant time.   template <class... Args>   void emplace_front(Args&&... args)   {  this->emplace_after(this->cbefore_begin(), detail::forward_impl<Args>(args)...); }

⌨️ 快捷键说明

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