You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Martin Sebor <se...@roguewave.com> on 2007/10/22 20:24:32 UTC

Re: svn commit: r587164 - /incubator/stdcxx/branches/4.2.x/include/vector.cc

faridz@apache.org wrote:
> Author: faridz
> Date: Mon Oct 22 10:22:59 2007
> New Revision: 587164
> 
> URL: http://svn.apache.org/viewvc?rev=587164&view=rev
> Log:
> 2007-10-22 Farid Zaripov <fa...@epam.com>
> 
> 	STDCXX-495
> 	* vector.cc (_C_insert_1): Allow inserting the values from *this.
> 	If the value_type is a fundamental type, then save the inserting value
> 	in a temporary copy before the moving [it; end()) range toward to end.
> 	If the value_type is not a fundamental type, then save the pointer to
> 	the inserting value and adjust the pointer if the inserting value belongs
> 	to the range [it; end()).
> 
> Modified:
>     incubator/stdcxx/branches/4.2.x/include/vector.cc
> 
> Modified: incubator/stdcxx/branches/4.2.x/include/vector.cc
> URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/vector.cc?rev=587164&r1=587163&r2=587164&view=diff
> ==============================================================================
> --- incubator/stdcxx/branches/4.2.x/include/vector.cc (original)
> +++ incubator/stdcxx/branches/4.2.x/include/vector.cc Mon Oct 22 10:22:59 2007
> @@ -39,6 +39,8 @@
>   * 
>   **************************************************************************/
>  
> +#include <rw/_typetraits.h>   // for __rw_type_traits<>

Is this being used anywhere else in stdcxx yet? If not, I'd rather
hold off introducing it until 4.3 (there's a better way to design
the traits classes and some compilers, including MSVC 8, have an
intrinsic implementation of some of these critters so it would
be nice to use them wherever available).

> +
>  _RWSTD_NAMESPACE (std) { 
>  
>  template <class _TypeT, class _Allocator>
> @@ -178,12 +180,38 @@
>              // and bump up end()
>              _C_push_back (*(_C_end - difference_type (1)));
>  
> -            // move the remaining elements from the range above one slot
> -            // toward the end starting with the last element
> -            _STD::copy_backward (__it, end () - 2, __end);
> -
> -            // overwrite the element at the given position
> -            *__it = __x;
> +            if (__rw::__rw_type_traits<value_type>::_C_is_class) {
> +                // save the pointer to allow inserting the value from self
> +                const value_type* __px = &__x;
> +
> +                if (&*__it < __px && __px < &*__end) {
> +                    // adjust the pointer if the inserting value
> +                    // belongs the range (__it; __end)
> +                    ++__px;
> +                } else if (&*__it == __px) {

The stdcxx formatting style calls for the closing curly brace
to be one a line of its own.

Martin

> +                    // reset the pointer to 0 to avoid
> +                    // self assignment __x = __x
> +                    __px = 0;
> +                }
> +
> +                // move the remaining elements from the range above one slot
> +                // toward the end starting with the last element
> +                _STD::copy_backward (__it, end () - 2, __end);
> +
> +                // overwrite the element at the given position
> +                if (__px)
> +                    *__it = *__px;
> +            } else {
> +                // save the copy to allow inserting the value from self
> +                const value_type __tmp = __x;
> +
> +                // move the remaining elements from the range above one slot
> +                // toward the end starting with the last element
> +                _STD::copy_backward (__it, end () - 2, __end);
> +
> +                // overwrite the element at the given position
> +                *__it = __tmp;
> +            }
>          }
>          else {
>              // construct a copy of the value to be inserted
> 
> 


RE: svn commit: r587164 - /incubator/stdcxx/branches/4.2.x/include/vector.cc

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Monday, October 22, 2007 9:25 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: svn commit: r587164 - 
> /incubator/stdcxx/branches/4.2.x/include/vector.cc
> 
> faridz@apache.org wrote:
> > Author: faridz
> > Date: Mon Oct 22 10:22:59 2007
> > New Revision: 587164
> > 
> > URL: http://svn.apache.org/viewvc?rev=587164&view=rev
> > Log:
> > 2007-10-22 Farid Zaripov <fa...@epam.com>
> > 
> > 	STDCXX-495

> Is this being used anywhere else in stdcxx yet? If not, I'd 
> rather hold off introducing it until 4.3 (there's a better 
> way to design the traits classes and some compilers, 
> including MSVC 8, have an intrinsic implementation of some of 
> these critters so it would be nice to use them wherever available).

  I've reverted the change and deferred the STDCXX-495 issue to 4.3
release.

Farid.