From: Dima Sorkin (dsorkin_at_[hidden])
Date: 2008-06-01 05:50:08
Please see below.
Quoting Hongzheng Wang <wanghz_at_[hidden]>:
> I scanned the archives of mailing lists for the usage of
> array_adaptor<>. It seems that the typical usage is as the following
> double extdat[N];
> array_adaptor<double> aa(N, extdat);
> vector<double, array_adaptor<double> > vd(N, aa);
> By tracing the codes, I found that aa and extdat are sharing the same
> raw data. That is, &aa.data() points to extdat. But vd does not
> shares the data. Instead, when vd is constructed, it seems that a
> copy of extdat is created to setup the new vector. So, I wonder what
> is the advantage of using array_adaptor. In other words, why not just
> use std::copy or even memcopy (if the layouts are contiguous) to do
> the same thing? Is there any special design purpose in inventing
AFAIK, it is to adapt a raw array and then use its contents (by copying).
Otherwise how would you create a ublas::vector from a raw data ?
For the aim of aliasing the data, there is a shallow_array_adaptor.
The concept of how a shallow array should work is not closed,
there were many other ideas, between them carray_adaptor in 1.32 release.