Thread Previous • Date Previous • Date Next • Thread Next |
Ola Skavhaug wrote:
On Wed, Aug 19, 2009 at 11:16 PM, Garth N. Wells<gnw20@xxxxxxxxx> wrote:Ola Skavhaug wrote:On Wed, Aug 19, 2009 at 8:30 PM, Garth N. Wells<gnw20@xxxxxxxxx> wrote:I didn't realise until recently that storage in std::vector is guaranteed by the C++ standard to be contiguous (versus only being contiguous in all known implementations). Using this, I think that we can have safer and cleaner code by using more std::vector in the linear algebra interface. For example, we could have GenericVector::get(std::vector<double>& ); GenericVector::set(const std::vector<double>& ); instead of GenericVector::get(double* x); GenericVector::set(const double* x); For backends that want a pointer to an array, we can pass &x[0]. Any opinions?I completely agree. I didn't know this either, but Google told me you're right, .i.e, that C++03 guarantees contiguity. Looking forward to C++0x when arrays will be contiguous as well.Not sure you mean about arrays. Do you mean multi-dimensional arrays?std::array or boost::tr1::array as it is called today. See: http://herbsutter.wordpress.com/2008/04/07/cringe-not-vectors-are-guaranteed-to-be-contiguous/ and http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/baa9b98c83e0b412?pli=1 boost::tr1::array are fixed size, and maps more directly to native c++ arrays. This might make issues like grabbing raw pointers less complicated.
Should we template get/set functions so one can use a std::vector or a boost::array, or even a boost::mult_array?
Garth
OlaGarthOlaGarth _______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@xxxxxxxxxx http://www.fenics.org/mailman/listinfo/dolfin-dev
Thread Previous • Date Previous • Date Next • Thread Next |