Paul Hilfinger wrote:
> > BTW: I observe that ISO C++ has a template function
> > std::uninitialized_copy, defined in <memory>, which ought to work for
> > copying a stack properly.
>
Hans Aberg wrote:
> The algorithm is
> for (; first != last; ++result, ++first)
> new (static_cast<void*>(&*result))
> typename iterator_traits<ForwardIterator>::value_type(*first);
>
> So it looks as it allocates for each iterator value, which isn't
> right. The C skeleton allocates a new block and then memcpy's over the
> data. Here one should iteratively call the copy-constructors. Then it
> might be easier to use std::vector or std::deque. Then using the C-
> skeleton start becoming complicated.
>
That's not what this means. The 'new' operator here uses the standard
placement form, which does no allocation, but uses the given address
(result) as the pointer value, invoking the copy constructor
(value_type(*first)) on it. This is indeed the desired behavior.
Paul
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison