list.hpp

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

HPP
1,478
字号
   //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).   //!    //! <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 unique()   {  this->unique(value_equal());  }   //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent    //!   elements that satisfy some binary predicate from the list.   //!    //! <b>Throws</b>: If pred throws.   //!    //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).   //!    //! <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 BinaryPredicate>   void unique(BinaryPredicate binary_pred)   {      typedef ValueCompareToNodeCompare<BinaryPredicate> Predicate;      this->icont().unique_and_dispose(Predicate(binary_pred), Destroyer(this->node_alloc()));   }   //! <b>Requires</b>: The lists x and *this must be distinct.    //!   //! <b>Effects</b>: This function removes all of x's elements and inserts them   //!   in order into *this according to std::less<value_type>. The merge is stable;    //!   that is, if an element from *this is equivalent to one from x, then the element    //!   from *this will precede the one from x.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: This function is linear time: it performs at most   //!   size() + x.size() - 1 comparisons.   void merge(list<T, A>& x)   {  this->merge(x, value_less());  }   //! <b>Effects</b>: This function removes all of moved mx's elements and inserts them   //!   in order into *this according to std::less<value_type>. The merge is stable;    //!   that is, if an element from *this is equivalent to one from x, then the element    //!   from *this will precede the one from x.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: This function is linear time: it performs at most   //!   size() + x.size() - 1 comparisons.   //!   //! <b>Note</b>: Iterators and references to *this are not invalidated.   //void merge(const detail::moved_object<list<T, A> >& x)   //{  this->merge(x.get());  }   //! <b>Requires</b>: p must be a comparison function that induces a strict weak   //!   ordering and both *this and x must be sorted according to that ordering   //!   The lists x and *this must be distinct.    //!    //! <b>Effects</b>: This function removes all of x's elements and inserts them   //!   in order into *this. The merge is stable; that is, if an element from *this is    //!   equivalent to one from x, then the element from *this will precede the one from x.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: This function is linear time: it performs at most   //!   size() + x.size() - 1 comparisons.   //!    //! <b>Note</b>: Iterators and references to *this are not invalidated.   template <class StrictWeakOrdering>   void merge(list<T, A>& x, StrictWeakOrdering comp)   {      if((NodeAlloc&)*this == (NodeAlloc&)x){         this->icont().merge(x.icont(),            ValueCompareToNodeCompare<StrictWeakOrdering>(comp));      }      else{         throw std::runtime_error("list::merge called with unequal allocators");      }   }   //! <b>Requires</b>: p must be a comparison function that induces a strict weak   //!   ordering and both *this and x must be sorted according to that ordering   //!   The lists x and *this must be distinct.    //!    //! <b>Effects</b>: This function removes all of moved mx's elements and inserts them   //!   in order into *this. The merge is stable; that is, if an element from *this is    //!   equivalent to one from x, then the element from *this will precede the one from x.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: This function is linear time: it performs at most   //!   size() + x.size() - 1 comparisons.   //!    //! <b>Note</b>: Iterators and references to *this are not invalidated.   //template <class StrictWeakOrdering>   //void merge(const detail::moved_object<list<T, A> >& x, StrictWeakOrdering comp)   //{  return this->merge(x.get(), comp);  }   //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.    //!   The sort is stable, that is, the relative order of equivalent elements is preserved.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Notes</b>: Iterators and references are not invalidated.   //!      //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N   //!   is the list's size.   void sort()   {  this->sort(value_less());  }   //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.    //!   The sort is stable, that is, the relative order of equivalent elements is preserved.   //!    //! <b>Throws</b>: Nothing.   //!   //! <b>Notes</b>: Iterators and references are not invalidated.   //!    //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N   //!   is the list's size.   template <class StrictWeakOrdering>   void sort(StrictWeakOrdering comp)   {      // nothing if the list has length 0 or 1.      if (this->size() < 2)         return;      this->icont().sort(ValueCompareToNodeCompare<StrictWeakOrdering>(comp));   }   /// @cond   private:   //Iterator range version   template<class InpIterator>   void priv_create_and_insert_nodes      (const_iterator pos, InpIterator beg, InpIterator end)   {      typedef typename std::iterator_traits<InpIterator>::iterator_category ItCat;      priv_create_and_insert_nodes(pos, beg, end, alloc_version(), ItCat());   }   template<class InpIterator>   void priv_create_and_insert_nodes      (const_iterator pos, InpIterator beg, InpIterator end, allocator_v1, std::input_iterator_tag)   {      for (; beg != end; ++beg){         this->icont().insert(pos.get(), *this->create_node_from_it(beg));      }   }   template<class InpIterator>   void priv_create_and_insert_nodes      (const_iterator pos, InpIterator beg, InpIterator end, allocator_v2, std::input_iterator_tag)   {  //Just forward to the default one      priv_create_and_insert_nodes(pos, beg, end, allocator_v1(), std::input_iterator_tag());   }   class insertion_functor;   friend class insertion_functor;   class insertion_functor   {      Icont &icont_;      typename Icont::const_iterator pos_;      public:      insertion_functor(Icont &icont, typename Icont::const_iterator pos)         :  icont_(icont), pos_(pos)      {}      void operator()(Node &n)      {  this->icont_.insert(pos_, n); }   };   template<class FwdIterator>   void priv_create_and_insert_nodes      (const_iterator pos, FwdIterator beg, FwdIterator end, allocator_v2, std::forward_iterator_tag)   {      //Optimized allocation and construction      this->allocate_many_and_construct         (beg, std::distance(beg, end), insertion_functor(this->icont(), pos.get()));   }   //Default constructed version   void priv_create_and_insert_nodes(const_iterator pos, size_type n)   {      typedef default_construct_iterator<value_type, difference_type> default_iterator;      this->priv_create_and_insert_nodes(pos, default_iterator(n), default_iterator());   }   //Copy constructed version   void priv_create_and_insert_nodes(const_iterator pos, size_type n, const T& x)   {      typedef constant_iterator<value_type, difference_type> cvalue_iterator;      this->priv_create_and_insert_nodes(pos, cvalue_iterator(x, n), cvalue_iterator());   }   //Dispatch to detect iterator range or integer overloads   template <class InputIter>   void priv_insert_dispatch(const_iterator p,                             InputIter first, InputIter last,                             detail::false_)   {  this->priv_create_and_insert_nodes(p, first, last);   }   template<class Integer>   void priv_insert_dispatch(const_iterator p, Integer n, Integer x, detail::true_)    {  this->insert(p, (size_type)n, x);  }   void priv_fill_assign(size_type n, const T& val)    {      iterator i = this->begin(), iend = this->end();      for ( ; i != iend && n > 0; ++i, --n)         *i = val;      if (n > 0){         this->priv_create_and_insert_nodes(this->cend(), n, val);      }      else{         this->erase(i, cend());      }   }   template <class Integer>   void priv_assign_dispatch(Integer n, Integer val, detail::true_)   {  this->priv_fill_assign((size_type) n, (T) val); }   template <class InputIter>   void priv_assign_dispatch(InputIter first2, InputIter last2, detail::false_)   {      iterator first1   = this->begin();      iterator last1    = this->end();      for ( ; first1 != last1 && first2 != last2; ++first1, ++first2)         *first1 = *first2;      if (first2 == last2)         this->erase(first1, last1);      else{         this->priv_create_and_insert_nodes(last1, first2, last2);      }   }   //Functors for member algorithm defaults   struct value_less   {      bool operator()(const value_type &a, const value_type &b) const         {  return a < b;  }   };   struct value_equal   {      bool operator()(const value_type &a, const value_type &b) const         {  return a == b;  }   };   /// @endcond};template <class T, class A>inline bool operator==(const list<T,A>& x, const list<T,A>& y){   if(x.size() != y.size()){      return false;   }   typedef typename list<T,A>::const_iterator const_iterator;   const_iterator end1 = x.end();   const_iterator i1 = x.begin();   const_iterator i2 = y.begin();   while (i1 != end1 && *i1 == *i2) {      ++i1;      ++i2;   }   return i1 == end1;}template <class T, class A>inline bool operator<(const list<T,A>& x,                      const list<T,A>& y){  return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());}template <class T, class A>inline bool operator!=(const list<T,A>& x, const list<T,A>& y) {  return !(x == y);}template <class T, class A>inline bool operator>(const list<T,A>& x, const list<T,A>& y) {  return y < x;}template <class T, class A>inline bool operator<=(const list<T,A>& x, const list<T,A>& y) {  return !(y < x);}template <class T, class A>inline bool operator>=(const list<T,A>& x, const list<T,A>& y) {  return !(x < y);}#ifndef BOOST_INTERPROCESS_RVALUE_REFERENCEtemplate <class T, class A>inline void swap(list<T, A>& x, list<T, A>& y){  x.swap(y);}template <class T, class A>inline void swap(const detail::moved_object<list<T, A> >& x, list<T, A>& y){  x.get().swap(y);}template <class T, class A>inline void swap(list<T, A>& x, const detail::moved_object<list<T, A> >& y){  x.swap(y.get());}#elsetemplate <class T, class A>inline void swap(list<T, A> &&x, list<T, A> &&y){  x.swap(y);}#endif/// @cond//!This class is movabletemplate <class T, class A>struct is_movable<list<T, A> >{   enum {   value = true };};//!This class is movabletemplate <class T, class VoidPointer>struct is_movable<detail::list_node<T, VoidPointer> >{   enum {   value = true };};/*//!This class is movabletemplate <class A>struct is_movable<detail::list_alloc<A> >{   enum {   value = true };};*///!has_trivial_destructor_after_move<> == true_type//!specialization for optimizationstemplate <class T, class A>struct has_trivial_destructor_after_move<list<T, A> >{   enum {   value = has_trivial_destructor<A>::value  };};/// @endcond}  //namespace interprocess {}  //namespace boost {#include <boost/interprocess/detail/config_end.hpp>#endif // BOOST_INTERPROCESS_LIST_HPP_

⌨️ 快捷键说明

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