Re: creation of matrix elements

Neal Becker <[email protected]> Sun, 23 Dec 2007 07:01:23 -0500
Newsgroups gmane.comp.lib.mtl.devel
Message-ID <[email protected]>
On Sunday 23 December 2007, Michael Smolsky wrote:
> Thank you for your insight, Peter.
>
> By looking at your code (contiguous_memory_block.hpp,
> generic_array<..>::alloc(..)) I've noticed, that you don't initialize
> matrix elements on allocation. That method seems to be called from some
> methods of dense2D, such as resize(..). If that is the case, the library
> won't work with any class, that has a non-trivial default constructor.
>

If you look at the current boost::ublas, you'll find e.g.:

        unbounded_array (size_type size, const ALLOC &a = ALLOC()):
            alloc_(a), size_ (size) {
          if (size_) {
              data_ = alloc_.allocate (size_);
              if (! detail::has_trivial_constructor<T>::value) {
                  for (pointer d = data_; d != data_ + size_; ++d)
                      alloc_.construct(d, value_type());
 
also:
    namespace detail {

        // specialisation which define whether a type has a trivial 
constructor
        // or not. This is used by array types.
        template<typename T>
        struct has_trivial_constructor : public 
boost::has_trivial_constructor<T> {};

        template<typename T>
        struct has_trivial_destructor : public 
boost::has_trivial_destructor<T> {};

        template<typename FLT>
        struct has_trivial_constructor<std::complex<FLT> > : public 
boost::true_type {};
        
        template<typename FLT>
        struct has_trivial_destructor<std::complex<FLT> > : public 
boost::true_type {};

    }

I believe this is a good approach
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/