list.hpp

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

HPP
1,478
字号
      if (this != &x) {         this->assign(x.begin(), x.end());      }      return *this;   }   //! <b>Effects</b>: Move assignment. All mx's values are transferred to *this.   //!   //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had   //!   before the function.   //!   //! <b>Throws</b>: If allocator_type's copy constructor throws.   //!   //! <b>Complexity</b>: Constant.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   ThisType& operator=(const detail::moved_object<ThisType>& mx)   {      this->clear();      this->swap(mx.get());      return *this;   }   #else   ThisType& operator=(ThisType &&mx)   {      this->clear();      this->swap(mx);      return *this;   }   #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.   void insert(const_iterator p, size_type n, const T& x)   { this->priv_create_and_insert_nodes(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).   template <class InpIt>   void insert(const_iterator p, InpIt first, InpIt last)    {      const bool aux_boolean = detail::is_convertible<InpIt, std::size_t>::value;      typedef detail::bool_<aux_boolean> Result;      this->priv_insert_dispatch(p, 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>: Amortized constant time.   iterator insert(const_iterator p, const T& x)    {      NodePtr tmp = AllocHolder::create_node(x);      return iterator(this->icont().insert(p.get(), *tmp));   }   //! <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>: Amortized constant time.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   iterator insert(const_iterator p, const detail::moved_object<T>& x)    {      NodePtr tmp = AllocHolder::create_node(x);      return iterator(this->icont().insert(p.get(), *tmp));   }   #else   iterator insert(const_iterator p, T &&x)    {      NodePtr tmp = AllocHolder::create_node(detail::move_impl(x));      return iterator(this->icont().insert(p.get(), *tmp));   }   #endif   #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING   //! <b>Effects</b>: Inserts an object of type T constructed with   //!   std::forward<Args>(args)... in the end of the list.   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's in-place constructor throws.   //!   //! <b>Complexity</b>: Constant   template <class... Args>   void emplace_back(Args&&... args)   {      this->emplace(this->cend(), detail::forward_impl<Args>(args)...);   }   //! <b>Effects</b>: Inserts an object of type T constructed with   //!   std::forward<Args>(args)... in the beginning of the list.   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's in-place constructor throws.   //!   //! <b>Complexity</b>: Constant   template <class... Args>   void emplace_front(Args&&... args)   {      this->emplace(this->cbegin(), detail::forward_impl<Args>(args)...);   }   //! <b>Effects</b>: Inserts an object of type T constructed with   //!   std::forward<Args>(args)... before p.   //!   //! <b>Throws</b>: If memory allocation throws or   //!   T's in-place constructor throws.   //!   //! <b>Complexity</b>: Constant   template <class... Args>   iterator emplace(const_iterator p, Args&&... args)   {      typename AllocHolder::Deallocator d(AllocHolder::create_node_and_deallocator());      new ((void*)detail::get_pointer(d.get())) Node(detail::forward_impl<Args>(args)...);      NodePtr node = d.get();      d.release();      return iterator(this->icont().insert(p.get(), *node));   }   #else //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING   //0 args   void emplace_back()   {  this->emplace(this->cend());  }   void emplace_front()   {  this->emplace(this->cbegin());   }   iterator emplace(const_iterator p)   {      typename AllocHolder::Deallocator d(AllocHolder::create_node_and_deallocator());      new ((void*)detail::get_pointer(d.get())) Node();      NodePtr node = d.get();      d.release();      return iterator(this->icont().insert(p.get(), *node));   }   #define BOOST_PP_LOCAL_MACRO(n)                                                              \   template<BOOST_PP_ENUM_PARAMS(n, class P)>                                                   \   void emplace_back(BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_LIST, _))                     \   {                                                                                            \      this->emplace(this->cend(), BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_FORWARD, _));    \   }                                                                                            \                                                                                                \   template<BOOST_PP_ENUM_PARAMS(n, class P)>                                                   \   void emplace_front(BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_LIST, _))                    \   {  this->emplace(this->cbegin(), BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_FORWARD, _));} \                                                                                                \   template<BOOST_PP_ENUM_PARAMS(n, class P)>                                                   \   iterator emplace(const_iterator p, BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_LIST, _))    \   {                                                                                            \      typename AllocHolder::Deallocator d(AllocHolder::create_node_and_deallocator());          \      new ((void*)detail::get_pointer(d.get()))                                                 \         Node(BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_FORWARD, _));                        \      NodePtr node = d.get();                                                                   \      d.release();                                                                              \      return iterator(this->icont().insert(p.get(), *node));                                    \   }                                                                                            \   //!   #define BOOST_PP_LOCAL_LIMITS (1, BOOST_INTERPROCESS_MAX_CONSTRUCTOR_PARAMETERS)   #include BOOST_PP_LOCAL_ITERATE()   #endif   //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING   //! <b>Requires</b>: p must be a valid iterator of *this.   //!   //! <b>Effects</b>: Erases the element at p p.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Amortized constant time.   iterator erase(const_iterator p)    {  return iterator(this->icont().erase_and_dispose(p.get(), Destroyer(this->node_alloc()))); }   //! <b>Requires</b>: first and last must be valid iterator to elements in *this.   //!   //! <b>Effects</b>: Erases the elements pointed by [first, last).   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Linear to the distance between first and last.   iterator erase(const_iterator first, const_iterator last)   {  return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version())); }   //! <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 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>Requires</b>: p must point to an element contained   //!   by the list. x != *this   //!   //! <b>Effects</b>: Transfers all the elements of list x to this list, before the   //!   the element pointed by p. No destructors or copy constructors are called.   //!   //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator   //!   are not equal.   //!   //! <b>Complexity</b>: Constant.   //!    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of   //!    this list. Iterators of this list and all the references are not invalidated.   void splice(iterator p, ThisType& x)    {      if((NodeAlloc&)*this == (NodeAlloc&)x){         this->icont().splice(p.get(), x.icont());      }      else{         throw std::runtime_error("list::splice called with unequal allocators");      }   }//   void splice(iterator p, const detail::moved_object<ThisType>& x) //   {  this->splice(p, x.get());  }   //! <b>Requires</b>: p must point to an element contained   //!   by this list. i must point to an element contained in list x.   //!    //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,    //!   before the the element pointed by p. No destructors or copy constructors are called.   //!   If p == i or p == ++i, this function is a null operation.    //!    //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator   //!   are not equal.   //!    //! <b>Complexity</b>: Constant.   //!    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this   //!   list. Iterators of this list and all the references are not invalidated.   void splice(const_iterator p, ThisType &x, const_iterator i)    {      if((NodeAlloc&)*this == (NodeAlloc&)x){         this->icont().splice(p.get(), x.icont(), i.get());      }      else{         throw std::runtime_error("list::splice called with unequal allocators");      }   }//   void splice(const_iterator p, const detail::moved_object<ThisType> &x, const_iterator i) //   {  this->splice(p, x.get(), i);  }   //! <b>Requires</b>: p must point to an element contained   //!   by this list. first and last must point to elements contained in list x.   //!    //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,    //!   before the the element pointed by p. No destructors or copy constructors are called.   //!    //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator   //!   are not equal.   //!    //! <b>Complexity</b>: Linear to the number of elements transferred.   //!    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this   //!   list. Iterators of this list and all the references are not invalidated.   void splice(const_iterator p, ThisType &x, const_iterator first, const_iterator last)    {      if((NodeAlloc&)*this == (NodeAlloc&)x){         this->icont().splice(p.get(), x.icont(), first.get(), last.get());      }      else{         throw std::runtime_error("list::splice called with unequal allocators");      }   }//   void splice(const_iterator p, detail::moved_object<ThisType> &x, const_iterator first, const_iterator last) //   {  return this->splice(p, x.get(), first, last);   }   //! <b>Requires</b>: p must point to an element contained   //!   by this list. first and last must point to elements contained in list x.   //!   n == std::distance(first, last)   //!    //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,    //!   before the the element pointed by p. No destructors or copy constructors are called.   //!    //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator   //!   are not equal.   //!    //! <b>Complexity</b>: Constant.   //!    //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this   //!   list. Iterators of this list and all the references are not invalidated.   void splice(const_iterator p, ThisType &x, const_iterator first, const_iterator last, size_type n)    {      if((NodeAlloc&)*this == (NodeAlloc&)x){         this->icont().splice(p.get(), x.icont(), first.get(), last.get(), n);      }      else{         throw std::runtime_error("list::splice called with unequal allocators");      }   }//   void splice(const_iterator p, detail::moved_object<ThisType> &x, const_iterator first, const_iterator last, size_type n) //   {  return this->splice(p, x.get(), first, last, n);   }   //! <b>Effects</b>: Reverses the order of elements in the list.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: This function is linear time.   //!    //! <b>Note</b>: Iterators and references are not invalidated   void reverse()   {  this->icont().reverse(); }       //! <b>Effects</b>: Removes all the elements that compare equal to value.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.   //!    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,   //!   and iterators to elements that are not removed remain valid.   void remove(const T& value)   {  remove_if(equal_to_value(value));  }   //! <b>Effects</b>: Removes all the elements for which a specified   //!   predicate is satisfied.   //!    //! <b>Throws</b>: If pred throws.   //!    //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.   //!    //! <b>Note</b>: The relative order of elements that are not removed is unchanged,   //!   and iterators to elements that are not removed remain valid.   template <class Pred>   void remove_if(Pred pred)   {      typedef ValueCompareToNodeCompare<Pred> Predicate;      this->icont().remove_and_dispose_if(Predicate(pred), Destroyer(this->node_alloc()));   }   //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent    //!   elements that are equal from the list.   //!    //! <b>Throws</b>: Nothing.   //! 

⌨️ 快捷键说明

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