Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81952 - sandbox-branches/geometry/index/boost/geometry/extensions/index
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-14 16:26:15


Author: awulkiew
Date: 2012-12-14 16:26:14 EST (Fri, 14 Dec 2012)
New Revision: 81952
URL: http://svn.boost.org/trac/boost/changeset/81952

Log:
static_vector resize() and corresponding ctor divided into 2 methods/ctors (C++11).

First one uses default ctors (for noncopyable values).
Second one uses copy ctors (for values with no default ctor).
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp | 47 +++++++++++++++++++++++++++++++--------
   1 files changed, 37 insertions(+), 10 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-14 16:26:14 EST (Fri, 14 Dec 2012)
@@ -52,7 +52,14 @@
     {}
 
     // strong
- explicit static_vector(size_type s, value_type const& value = value_type())
+ explicit static_vector(size_type s)
+ : m_size(0)
+ {
+ resize(s); // may throw
+ }
+
+ // strong
+ static_vector(size_type s, value_type const& value)
         : m_size(0)
     {
         resize(s, value); // may throw
@@ -73,7 +80,7 @@
     {
         //BOOST_ASSERT_MSG(other.m_size <= Capacity, "capacity too small");
 
- this->assign(other->ptr(0), other->ptr(other.m_size));
+ assign(other->ptr(0), other->ptr(other.m_size));
 
         return *this;
     }
@@ -86,7 +93,25 @@
     }
 
     // strong
- void resize(size_type s, value_type const& value = value_type())
+ void resize(size_type s)
+ {
+ if ( s < m_size )
+ {
+ this->destroy(this->ptr(s), this->ptr(m_size),
+ boost::has_trivial_destructor<value_type>());
+ m_size = s;
+ }
+ else
+ {
+ BOOST_ASSERT_MSG(s <= Capacity, "size can't exceed the capacity");
+ this->construct(this->ptr(m_size), this->ptr(s)
+ boost::has_trivial_constructor<value_type>()); // may throw
+ m_size = s;
+ }
+ }
+
+ // strong
+ void resize(size_type s, value_type const& value)
     {
         if ( s < m_size )
         {
@@ -97,7 +122,7 @@
         else
         {
             BOOST_ASSERT_MSG(s <= Capacity, "size can't exceed the capacity");
- this->uninitialized_fill(this->ptr(m_size), this->ptr(s), value); // may throw
+ std::uninitialized_fill(this->ptr(m_size), this->ptr(s), value); // may throw
             m_size = s;
         }
     }
@@ -111,8 +136,6 @@
     // strong
     void push_back(Value const& value)
     {
- if ( Capacity <= m_size )
- std::cout << m_size << '\n';
         BOOST_ASSERT_MSG(m_size < Capacity, "max capacity reached");
         this->uninitialized_copy(this->ptr(m_size), value,
                                  boost::has_trivial_copy<value_type>()); // may throw
@@ -277,7 +300,7 @@
     void uninitialized_copy(value_type * ptr, value_type const& v,
                             boost::false_type const& /*has_trivial_copy*/)
     {
- new (ptr) value_type(v); // may throw
+ new (ptr) value_type(v); // may throw
     }
 
     void destroy(const value_type *, const value_type *,
@@ -300,14 +323,14 @@
         ptr->~value_type();
     }
 
- void uninitialized_fill(value_type * first, value_type * last, value_type const& value)
+ void construct(value_type * first, value_type * last,
+ boost::true_type const& /*has_trivial_constructor*/)
     {
- // std::uninitialized_fill()
         value_type * it = first;
         try
         {
             for ( ; it != last ; ++it )
- new (it) value_type(value); // may throw
+ new (it) value_type(); // may throw
         }
         catch(...)
         {
@@ -316,6 +339,10 @@
         }
     }
 
+ void construct(value_type * first, value_type * last,
+ boost::false_type const& /*has_trivial_constructor*/)
+ {}
+
     Value * ptr(size_type i)
     {
         return (reinterpret_cast<Value*>(m_storage.address()) + 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