libc++: First cut at <dynarray>

Marshall Clow mclow.lists at gmail.com
Thu Sep 12 18:57:32 PDT 2013


On Sep 12, 2013, at 6:23 PM, Howard Hinnant <howard.hinnant at gmail.com> wrote:

> Need to decrement __data prior to the destruction instead of after:
> 
> template <class _Tp>
> inline _LIBCPP_INLINE_VISIBILITY
> dynarray<_Tp>::~dynarray()
> { 
>    value_type *__data = data () + __size_;
>    for ( size_t i = 0; i < __size_; ++i )
>    {
>        --__data;
>        __data->value_type::~value_type();
>    }
>    __deallocate ( __base_ );
> }

Yesterday, I changed this to:

+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+dynarray<_Tp>::~dynarray()
+{ 
+    value_type *__data = data () + __size_;
+    for ( size_t i = 0; i < __size_; ++i )
+        (--__data)->value_type::~value_type();
+    __deallocate ( __base_ );
+}


Richard wrote:
> Hmm, what should size() return if it's called during the destruction of the dynarray?

Once we've entered the destructor, the object has ceased to be. It is an ex-object.

> During construction, it returns the number of fully-constructed elements. Maybe we should do the same here:

That's done because it makes the cleanup easier, rather than worrying about people calling methods on the object during the constructor.

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists at gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki





More information about the cfe-commits mailing list