Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82330 - in sandbox/static_vector: boost/container test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-01-03 09:04:10


Author: awulkiew
Date: 2013-01-03 09:04:08 EST (Thu, 03 Jan 2013)
New Revision: 82330
URL: http://svn.boost.org/trac/boost/changeset/82330

Log:
Type returned by data() changed from pointer to Value*. Description added.
Text files modified:
   sandbox/static_vector/boost/container/static_vector.hpp | 101 +++++++++++++++++++++++++++++++++++----
   sandbox/static_vector/test/static_vector_interprocess_test.cpp | 6 ++
   sandbox/static_vector/test/static_vector_test.cpp | 1
   3 files changed, 96 insertions(+), 12 deletions(-)

Modified: sandbox/static_vector/boost/container/static_vector.hpp
==============================================================================
--- sandbox/static_vector/boost/container/static_vector.hpp (original)
+++ sandbox/static_vector/boost/container/static_vector.hpp 2013-01-03 09:04:08 EST (Thu, 03 Jan 2013)
@@ -528,6 +528,8 @@
         ++m_size; // update end
     }
 
+ //! <b>Requires</b>: !empty().
+ //!
     //! <b>Effects</b>: Destroys last value and decreases the size.
     //!
     //! <b>Throws</b>: Nothing by default.
@@ -542,6 +544,8 @@
         --m_size; // update end
     }
 
+ //! <b>Requires</b>: position must be a valid iterator of *this in range [begin(), end()].
+ //!
     //! <b>Effects</b>: Inserts a copy of element at position.
     //!
     //! <b>Throws</b>: If Value's copy constructor or copy assignment throws
@@ -554,6 +558,8 @@
         return this->priv_insert(position, value);
     }
 
+ //! <b>Requires</b>: position must be a valid iterator of *this in range [begin(), end()].
+ //!
     //! <b>Effects</b>: Inserts a move-constructed element at position.
     //!
     //! <b>Throws</b>: If Value's move constructor or move assignment throws.
@@ -565,6 +571,8 @@
         return this->priv_insert(position, value);
     }
 
+ //! <b>Requires</b>: position must be a valid iterator of *this in range [begin(), end()].
+ //!
     //! <b>Effects</b>: Inserts a count copies of value at position.
     //!
     //! <b>Throws</b>: If Value's copy constructor or copy assignment throws
@@ -610,6 +618,8 @@
         return position;
     }
 
+ //! <b>Requires</b>: position must be a valid iterator of *this in range [begin(), end()].
+ //!
     //! <b>Effects</b>: Inserts a copy of a range [first, last) at position.
     //!
     //! <b>Throws</b>: If Value's constructor and assignment taking a dereferenced Iterator throws
@@ -628,6 +638,8 @@
         return position;
     }
 
+ //! <b>Requires</b>: position must be a valid iterator of *this in range [begin(), end()).
+ //!
     //! <b>Effects</b>: Erases Value from position.
     //!
     //! <b>Throws</b>: If Value's move assignment throws.
@@ -649,6 +661,8 @@
         return position;
     }
 
+ //! <b>Requires</b>: first and last must define a valid range, iterators must be in range [begin(), end()].
+ //!
     //! <b>Effects</b>: Erases Values from a range [first, last).
     //!
     //! <b>Throws</b>: If Value's move assignment throws.
@@ -841,7 +855,13 @@
         m_size = 0; // update end
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_at().
+ //! <b>Requires</b>: i < size().
+ //!
+ //! <b>Effects</b>: Returns a reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: std::out_of_range exception by default.
+ //!
     //! <b>Complexity</b>: Constant.
     reference at(size_type i)
     {
@@ -849,7 +869,13 @@
         return *(this->begin() + i);
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_at().
+ //! <b>Requires</b>: i < size().
+ //!
+ //! <b>Effects</b>: Returns a const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: std::out_of_range exception by default.
+ //!
     //! <b>Complexity</b>: Constant.
     const_reference at(size_type i) const
     {
@@ -857,7 +883,13 @@
         return *(this->begin() + i);
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_operator_brackets().
+ //! <b>Requires</b>: i < size().
+ //!
+ //! <b>Effects</b>: Returns a reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing by default.
+ //!
     //! <b>Complexity</b>: Constant.
     reference operator[](size_type i)
     {
@@ -865,7 +897,13 @@
         return *(this->begin() + i);
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_operator_brackets().
+ //! <b>Requires</b>: i < size().
+ //!
+ //! <b>Effects</b>: Returns a const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing by default.
+ //!
     //! <b>Complexity</b>: Constant.
     const_reference operator[](size_type i) const
     {
@@ -873,7 +911,13 @@
         return *(this->begin() + i);
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_empty().
+ //! <b>Requires</b>: !empty().
+ //!
+ //! <b>Effects</b>: Returns a reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing by default.
+ //!
     //! <b>Complexity</b>: Constant.
     reference front()
     {
@@ -881,7 +925,13 @@
         return *(this->begin());
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_empty().
+ //! <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 by default.
+ //!
     //! <b>Complexity</b>: Constant.
     const_reference front() const
     {
@@ -889,7 +939,13 @@
         return *(this->begin());
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_empty().
+ //! <b>Requires</b>: !empty().
+ //!
+ //! <b>Effects</b>: Returns a reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing by default.
+ //!
     //! <b>Complexity</b>: Constant.
     reference back()
     {
@@ -897,7 +953,13 @@
         return *(this->end() - 1);
     }
 
- //! <b>Throws</b>: If the Strategy throws in check_empty().
+ //! <b>Requires</b>: !empty().
+ //!
+ //! <b>Effects</b>: Returns a const reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing by default.
+ //!
     //! <b>Complexity</b>: Constant.
     const_reference back() const
     {
@@ -905,12 +967,27 @@
         return *(this->end() - 1);
     }
 
+ //! <b>Returns</b>: Pointer such that [data(), data() + size()) is a valid range.
+ //! For a non-empty vector, data() == &front().
+ //!
     //! <b>Throws</b>: Nothing.
+ //!
     //! <b>Complexity</b>: Constant.
- pointer data() { return boost::addressof(*(this->ptr())); }
+ Value * data()
+ {
+ return boost::addressof(*(this->ptr()));
+ }
+
+ //! <b>Returns</b>: Const pointer such that [data(), data() + size()) is a valid range.
+ //! For a non-empty vector, data() == &front().
+ //!
     //! <b>Throws</b>: Nothing.
+ //!
     //! <b>Complexity</b>: Constant.
- const_pointer data() const { return boost::addressof(*(this->ptr())); }
+ const Value * data() const
+ {
+ return boost::addressof(*(this->ptr()));
+ }
 
     //! <b>Throws</b>: Nothing.
     //! <b>Complexity</b>: Constant.
@@ -1504,8 +1581,8 @@
     }
 
     // nothrow
- pointer data() { return boost::addressof(*(this->ptr())); }
- const_pointer data() const { return boost::addressof(*(this->ptr())); }
+ Value * data() { return boost::addressof(*(this->ptr())); }
+ const Value * data() const { return boost::addressof(*(this->ptr())); }
 
     // nothrow
     iterator begin() { return this->ptr(); }

Modified: sandbox/static_vector/test/static_vector_interprocess_test.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector_interprocess_test.cpp (original)
+++ sandbox/static_vector/test/static_vector_interprocess_test.cpp 2013-01-03 09:04:08 EST (Thu, 03 Jan 2013)
@@ -59,6 +59,12 @@
     for ( size_t i = 0 ; i < N ; ++i )
         BOOST_CHECK((*sv_ptr)[i] == T(i + 1));
 
+ {
+ T * p = sv_ptr->data();
+ for ( size_t i = 0 ; p != sv_ptr->data() + sv_ptr->size() ; ++p, ++i )
+ BOOST_CHECK(*p == T(i + 1));
+ }
+
     sv_ptr->assign(N/2, t);
     for ( size_t i = 0 ; i < N/2 ; ++i )
         BOOST_CHECK(sv_ptr->at(i) == t);

Modified: sandbox/static_vector/test/static_vector_test.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector_test.cpp (original)
+++ sandbox/static_vector/test/static_vector_test.cpp 2013-01-03 09:04:08 EST (Thu, 03 Jan 2013)
@@ -173,6 +173,7 @@
         BOOST_CHECK(T(i) == s[i]);
         BOOST_CHECK(T(i) == s.back());
         BOOST_CHECK(T(0) == s.front());
+ BOOST_CHECK(T(i) == *(s.data() + i));
     }
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk