diff -r bd84f19955f3 boost/numeric/ublas/storage.hpp --- a/boost/numeric/ublas/storage.hpp Mon Jan 22 00:40:33 2007 +0000 +++ b/boost/numeric/ublas/storage.hpp Sat Feb 03 11:03:33 2007 -0500 @@ -22,11 +22,31 @@ #include #endif +#include +#include +#include + #include #include +#include +#include namespace boost { namespace numeric { namespace ublas { +namespace detail { + template + struct has_trivial_constructor : public boost::has_trivial_constructor {}; + + template + struct has_trivial_destructor : public boost::has_trivial_destructor {}; + + template + struct has_trivial_constructor > : public boost::true_type {}; + + template + struct has_trivial_destructor > : public boost::true_type {}; +}; + // Base class for Storage Arrays - see the Barton Nackman trick @@ -63,17 +83,14 @@ namespace boost { namespace numeric { na explicit BOOST_UBLAS_INLINE unbounded_array (size_type size, const ALLOC &a = ALLOC()): alloc_(a), size_ (size) { - if (size_) { - data_ = alloc_.allocate (size_); - // ISSUE some compilers may zero POD here -#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW - // array form fails on some compilers due to size cookie, is it standard conforming? - new (data_) value_type[size_]; -#else - for (pointer d = data_; d != data_ + size_; ++d) - new (d) value_type; -#endif - } + if (size_) { + data_ = alloc_.allocate (size_); + if (not detail::has_trivial_constructor::value) { + for (pointer d = data_; d != data_ + size_; ++d) + alloc_.construct(d, value_type()); + } + + } else data_ = 0; } @@ -100,13 +117,17 @@ namespace boost { namespace numeric { na } BOOST_UBLAS_INLINE ~unbounded_array () { - if (size_) { - const iterator i_end = end(); - for (iterator i = begin (); i != i_end; ++i) { - iterator_destroy (i); - } - alloc_.deallocate (data_, size_); - } + if (size_) { + if (not detail::has_trivial_destructor::value) { + // std::_Destroy (begin(), end(), alloc_); + const iterator i_end = end(); + for (iterator i = begin (); i != i_end; ++i) { + iterator_destroy (i); + } + } + + alloc_.deallocate (data_, size_); + } } // Resizing @@ -137,21 +158,19 @@ namespace boost { namespace numeric { na } } else { - // ISSUE some compilers may zero POD here -#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW - // array form fails on some compilers due to size cookie, is it standard conforming? - new (data_) value_type[size]; -#else + if (not detail::has_trivial_constructor::value) { for (pointer di = data_; di != data_ + size; ++di) - new (di) value_type; -#endif + alloc_.construct (di, value_type()); + } } } if (size_) { + if (not detail::has_trivial_destructor::value) { for (pointer si = p_data; si != p_data + size_; ++si) alloc_.destroy (si); - alloc_.deallocate (p_data, size_); + } + alloc_.deallocate (p_data, size_); } if (!size) @@ -267,6 +286,21 @@ namespace boost { namespace numeric { na // Allocator allocator_type get_allocator () { return alloc_; + } + + private: + friend class boost::serialization::access; + + // Serialization + template + void serialize(Archive & ar, const unsigned int version) + { + serialization::collection_size_type s(size_); + ar & serialization::make_nvp("size",s); + if ( Archive::is_loading::value ) { + resize(s); + } + ar & serialization::make_array(data_, s); } private: @@ -430,6 +464,22 @@ namespace boost { namespace numeric { na BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); + } + + private: + // Serialization + friend class boost::serialization::access; + + template + void serialize(Archive & ar, const unsigned int version) + { + serialization::collection_size_type s(size_); + ar & serialization::make_nvp("size", s); + if ( Archive::is_loading::value ) { + if (s > N) bad_size("too large size in bounded_array::load()\n").raise(); + resize(s); + } + ar & serialization::make_array(data_, s); } private: