list.hpp

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

HPP
1,478
字号
   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   list(const detail::moved_object<list> &x)      : AllocHolder(detail::move_impl((AllocHolder&)x.get()))   {}   #else   list(list &&x)      : AllocHolder(detail::move_impl((AllocHolder&)x))   {}   #endif   //! <b>Effects</b>: Constructs a list that will use a copy of allocator a   //!   and inserts a copy of the range [first, last) in the list.   //!   //! <b>Throws</b>: If allocator_type's default constructor or copy constructor   //!   throws or T's constructor taking an dereferenced InIt throws.   //!   //! <b>Complexity</b>: Linear to the range [first, last).   template <class InpIt>   list(InpIt first, InpIt last, const A &a = A())      : AllocHolder(a)   {  this->insert(this->cbegin(), first, last);  }   //! <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.   ~list()    {  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(); }   //! <b>Effects</b>: Erases all the elements of the list.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Linear to the number of elements in the list.   void clear()   {  AllocHolder::clear(alloc_version());  }   //! <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 reverse_iterator pointing to the beginning    //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   reverse_iterator rbegin()   {  return reverse_iterator(end());  }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning    //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator rbegin() const   {  return this->crbegin();  }   //! <b>Effects</b>: Returns a reverse_iterator pointing to the end   //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   reverse_iterator rend()   {  return reverse_iterator(begin());   }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end   //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator rend() const   {  return this->crend();   }   //! <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 const_reverse_iterator pointing to the beginning    //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator crbegin() const   {  return const_reverse_iterator(this->cend());  }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end   //! of the reversed list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator crend() const   {  return const_reverse_iterator(this->cbegin());   }   //! <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>: 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>: 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 T& x)      {  this->insert(this->cbegin(), 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->insert(this->cbegin(), x);  }   #else   void push_front(T &&x)      {  this->insert(this->cbegin(), detail::move_impl(x));  }   #endif   //! <b>Effects</b>: Removes the last element from the list.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Amortized constant time.   void push_back (const T& x)      {  this->insert(this->cend(), x);    }   //! <b>Effects</b>: Removes the first element from the list.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Amortized constant time.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   void push_back (const detail::moved_object<T>& x)      {  this->insert(this->cend(), x);    }   #else   void push_back (T &&x)      {  this->insert(this->cend(), 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->erase(this->cbegin());      }   //! <b>Effects</b>: Removes the last element from the list.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Amortized constant time.   void pop_back()                  {  const_iterator tmp = this->cend(); this->erase(--tmp);  }   //! <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>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 back()                 { return *(--this->end()); }   //! <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 back()  const    { return *(--this->end()); }   //! <b>Effects</b>: Inserts or erases elements at the end such that   //!   the size becomes n. New elements are copy constructed from x.   //!   //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to the difference between size() and new_size.   void resize(size_type new_size, const T& x)   {      const_iterator iend = this->cend();      size_type len = this->size();            if(len > new_size){         size_type to_erase = len - new_size;         while(to_erase--){            --iend;         }         this->erase(iend, this->cend());      }      else{         this->priv_create_and_insert_nodes(iend, new_size - len, x);      }   }   //! <b>Effects</b>: Inserts or erases elements at the end such that   //!   the size becomes n. New elements are default constructed.   //!   //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.   //!   //! <b>Complexity</b>: Linear to the difference between size() and new_size.   void resize(size_type new_size)   {      const_iterator iend = this->end();      size_type len = this->size();            if(len > new_size){         size_type to_erase = len - new_size;         const_iterator ifirst;         if(to_erase < len/2u){            ifirst = iend;            while(to_erase--){               --ifirst;            }         }         else{            ifirst = this->begin();            size_type to_skip = len - to_erase;            while(to_skip--){               ++ifirst;            }         }         this->erase(ifirst, iend);      }      else{         this->priv_create_and_insert_nodes(this->cend(), new_size - len);      }   }   //! <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>: Constant.   void swap(ThisType& x)   {  AllocHolder::swap(x);   }   //! <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>: Constant.   //void swap(const detail::moved_object<ThisType>& x)   //{  this->swap(x.get());  }   //! <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.   ThisType& operator=(const ThisType& x)   {

⌨️ 快捷键说明

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