# HG changeset patch # User ndbecker2@gmail.com # Date 1171998422 18000 # Node ID 42d2cedf48d31fe3e6f279c90cd51829335e7c67 # Parent d4dd463df34b8329559ec6d2fbdfb5bf5b10816e ublas bypass construction diff -r d4dd463df34b -r 42d2cedf48d3 boost/numeric/ublas/matrix.hpp --- a/boost/numeric/ublas/matrix.hpp Tue Feb 20 14:03:26 2007 -0500 +++ b/boost/numeric/ublas/matrix.hpp Tue Feb 20 14:07:02 2007 -0500 @@ -99,6 +99,10 @@ namespace boost { namespace numeric { na matrix_container (), size1_ (size1), size2_ (size2), data_ (layout_type::storage_size (size1, size2)) { } + matrix (size_type size1, size_type size2, const value_type &init): + matrix_container (), + size1_ (size1), size2_ (size2), data_ (layout_type::storage_size (size1, size2), init) { + } BOOST_UBLAS_INLINE matrix (size_type size1, size_type size2, const array_type &data): matrix_container (), diff -r d4dd463df34b -r 42d2cedf48d3 boost/numeric/ublas/storage.hpp --- a/boost/numeric/ublas/storage.hpp Tue Feb 20 14:03:26 2007 -0500 +++ b/boost/numeric/ublas/storage.hpp Tue Feb 20 14:07:02 2007 -0500 @@ -29,8 +29,24 @@ #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 @@ -67,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; } @@ -104,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 @@ -141,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) diff -r d4dd463df34b -r 42d2cedf48d3 boost/numeric/ublas/vector.hpp --- a/boost/numeric/ublas/vector.hpp Tue Feb 20 14:03:26 2007 -0500 +++ b/boost/numeric/ublas/vector.hpp Tue Feb 20 14:07:02 2007 -0500 @@ -65,6 +65,10 @@ namespace boost { namespace numeric { na vector_container (), data_ (data) {} BOOST_UBLAS_INLINE + vector (size_type size, const value_type &init): + vector_container (), + data_ (size, init) {} + BOOST_UBLAS_INLINE vector (const vector &v): vector_container (), data_ (v.data_) {}