vector.hpp

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

HPP
1,703
字号
         return std::pair<pointer, bool>(pointer(0), 0);      received_size = preferred_size;      return std::make_pair(this->alloc().allocate(received_size), false);   }   std::pair<pointer, bool>      allocation_command(allocation_type command,                         size_type limit_size,                          size_type preferred_size,                         size_type &received_size,                         const pointer &reuse,                         allocator_v2)   {      return this->alloc().allocation_command         (command, limit_size, preferred_size, received_size, reuse);   }   size_type next_capacity(size_type additional_objects) const   {  return get_next_capacity(this->alloc().max_size(), this->members_.m_capacity, additional_objects);  }   struct members_holder      : public A   {      private:      members_holder(const members_holder&);      public:      members_holder(const A &alloc)         :  A(alloc), m_start(0), m_size(0), m_capacity(0)      {}      pointer     m_start;      size_type   m_size;      size_type   m_capacity;   } members_;   protected:   void prot_deallocate()   {      if(!this->members_.m_capacity)   return;      this->alloc().deallocate(this->members_.m_start, this->members_.m_capacity);      this->members_.m_start     = 0;      this->members_.m_size      = 0;      this->members_.m_capacity  = 0;   }   void destroy(value_type* p)   {      if(!value_traits::trivial_dctr)         detail::get_pointer(p)->~value_type();   }   void destroy_n(value_type* p, size_type n)   {      if(!value_traits::trivial_dctr)         for(; n--; ++p)   p->~value_type();   }   A &alloc()   {  return members_;  }   const A &alloc() const   {  return members_;  }};}  //namespace detail {/// @endcond//! A vector is a sequence that supports random access to elements, constant //! time insertion and removal of elements at the end, and linear time insertion //! and removal of elements at the beginning or in the middle. The number of //! elements in a vector may vary dynamically; memory management is automatic.//! boost::interprocess::vector is similar to std::vector but it's compatible//! with shared memory and memory mapped files.template <class T, class A>class vector : private detail::vector_alloc_holder<A>{   /// @cond   typedef vector<T, A>                   self_t;   typedef detail::vector_alloc_holder<A> base_t;   /// @endcond   public:   //! The type of object, T, stored in the vector   typedef T                                       value_type;   //! Pointer to T   typedef typename A::pointer                     pointer;   //! Const pointer to T   typedef typename A::const_pointer               const_pointer;   //! Reference to T   typedef typename A::reference                   reference;   //! Const reference to T   typedef typename A::const_reference             const_reference;   //! An unsigned integral type   typedef typename A::size_type                   size_type;   //! A signed integral type   typedef typename A::difference_type             difference_type;   //! The allocator type   typedef A                                       allocator_type;   //! The random access iterator   typedef detail::vector_iterator<pointer>        iterator;   //! The random access const_iterator   typedef detail::vector_const_iterator<pointer>  const_iterator;   //! Iterator used to iterate backwards through a vector.    typedef std::reverse_iterator<iterator>         reverse_iterator;   //! Const iterator used to iterate backwards through a vector.    typedef std::reverse_iterator<const_iterator>                       const_reverse_iterator;   //! The stored allocator type   typedef allocator_type                          stored_allocator_type;   /// @cond   private:   typedef detail::advanced_insert_aux_int<T, T*>    advanced_insert_aux_int_t;   typedef detail::vector_value_traits<value_type, A> value_traits;   typedef typename base_t::allocator_v1           allocator_v1;   typedef typename base_t::allocator_v2           allocator_v2;   typedef typename base_t::alloc_version          alloc_version;   typedef constant_iterator<T, difference_type>   cvalue_iterator;   typedef repeat_iterator<T, difference_type>     repeat_it;   typedef detail::move_iterator<repeat_it>        repeat_move_it;   /// @endcond   public:   //! <b>Effects</b>: Constructs a vector taking the allocator as parameter.   //!    //! <b>Throws</b>: If allocator_type's copy constructor throws.   //!    //! <b>Complexity</b>: Constant.   explicit vector(const A& a = A())      : base_t(a)   {}   //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a   //!   and inserts n copies of value.   //!   //! <b>Throws</b>: If allocator_type's default constructor or copy constructor   //!   throws or T's default or copy constructor throws.   //!    //! <b>Complexity</b>: Linear to n.   vector(size_type n, const T& value = T(),          const allocator_type& a = allocator_type())       :  base_t(a)   {  this->insert(this->cend(), n, value); }   //! <b>Effects</b>: Copy constructs a vector.   //!   //! <b>Postcondition</b>: x == *this.   //!    //! <b>Complexity</b>: Linear to the elements x contains.   vector(const vector<T, A>& x)       :  base_t((base_t&)x)   {  *this = x;  }   //! <b>Effects</b>: Move constructor. Moves mx's resources to *this.   //!   //! <b>Throws</b>: If allocator_type's copy constructor throws.   //!    //! <b>Complexity</b>: Constant.   #ifndef BOOST_INTERPROCESS_RVALUE_REFERENCE   vector(const detail::moved_object<vector<T, A> >& mx)       :  base_t(mx.get())   {  this->swap(mx.get());   }   #else   vector(vector<T, A> && mx)       :  base_t(detail::move_impl(mx))   {  this->swap(mx);   }   #endif   //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a   //!   and inserts a copy of the range [first, last) in the vector.   //!   //! <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 InIt>   vector(InIt first, InIt last, const allocator_type& a = allocator_type())      :  base_t(a)   {  this->assign(first, last); }   //! <b>Effects</b>: Destroys the vector. All stored values are destroyed   //!   and used memory is deallocated.   //!   //! <b>Throws</b>: Nothing.   //!   //! <b>Complexity</b>: Linear to the number of elements.   ~vector()    {  this->priv_destroy_all();  }   //! <b>Effects</b>: Returns an iterator to the first element contained in the vector.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   iterator begin()         { return iterator(this->members_.m_start); }   //! <b>Effects</b>: Returns a const_iterator to the first element contained in the vector.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator begin() const   { return const_iterator(this->members_.m_start); }   //! <b>Effects</b>: Returns an iterator to the end of the vector.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   iterator end()           { return iterator(this->members_.m_start + this->members_.m_size); }   //! <b>Effects</b>: Returns a const_iterator to the end of the vector.   //!    //! <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 vector.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   reverse_iterator rbegin()        { return reverse_iterator(this->end());      }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning    //! of the reversed vector.    //!    //! <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 vector.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   reverse_iterator rend()          { return reverse_iterator(this->begin());       }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end   //! of the reversed vector.    //!    //! <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 vector.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator cbegin() const   { return const_iterator(this->members_.m_start); }   //! <b>Effects</b>: Returns a const_iterator to the end of the vector.   //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_iterator cend()   const   { return const_iterator(this->members_.m_start + this->members_.m_size); }   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning    //! of the reversed vector.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator crbegin()const   { return const_reverse_iterator(this->end());}   //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end   //! of the reversed vector.    //!    //! <b>Throws</b>: Nothing.   //!    //! <b>Complexity</b>: Constant.   const_reverse_iterator crend()  const   { return const_reverse_iterator(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         front()          { return *this->members_.m_start; }   //! <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->members_.m_start; }   //! <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->members_.m_start[this->members_.m_size - 1]; }   //! <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->members_.m_start[this->members_.m_size - 1]; }   //! <b>Returns</b>: A pointer such that [data(),data() + size()) is a valid range.   //!   For a non-empty vector, data() == &front().   //! 

⌨️ 快捷键说明

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