freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Freepooma-devel] Tiny/ all TrivialElementProperties!?


From: Richard Guenther
Subject: Re: [Freepooma-devel] Tiny/ all TrivialElementProperties!?
Date: Mon, 22 Nov 2004 16:50:56 +0100 (CET)

On Mon, 22 Nov 2004, Richard Guenther wrote:

> Hi!
>
> All Tiny classes define theirselves as having TrivialElementProperties
> which is correct only, if T is Trivial or Basic, but no checks are
> done for this.  Is this an intended requirement for accepted T or
> a bug?

A complete patch exploiting trivial element properties would look like
shown beyond.  Also have a look at the default engine constructor
which looks like


  // Null ctor takes no action.
  VectorEngine()
  {
    for (int i = 0; i < D; ++i)
      {
        ElementProperties<T>::construct(&x_m[i]);
      }
  }

it says "takes no action", but zero-initializes the storage.  This
is inefficient and looks like an oversight people may depend on?
At least the testsuite passes without zero-initialization - like
we do for TinyMatrix and Tensor.

Ok with the patch below?  Ok to remove the zero-initialization?

Thanks,
Richard.


Index: Vector.h
===================================================================
RCS file: /cvsroot/freepooma/freepooma/src/Tiny/Vector.h,v
retrieving revision 1.36
diff -u -u -r1.36 Vector.h
--- Vector.h    22 Nov 2004 15:28:00 -0000      1.36
+++ Vector.h    22 Nov 2004 15:50:39 -0000
@@ -66,7 +66,7 @@
 /**
  * Vector is an interface class that takes three template parameters:
  * - int Dim: The number of components in the vector.
- * - class T: The type of the components.
+ * - class T: The type of the components, must have trivial element properties.
  * - class EngineTag: A policy parameter for the storage type.
  */

@@ -102,9 +102,6 @@
   // Null ctor uses the engine's null ctor.
   Vector() {}

-  // Copy ctor is deep.
-  Vector(const This_t& x) : engine_m(x.engine_m) {}
-
   // Construct from an arbitrary single object.
   // The object must be indexable using VectorElem.
   template<class X>
@@ -140,14 +137,6 @@
   //----------------------------------------------------------------------
   // Assignment

-  // Assign from the same kind of vector.
-  This_t& operator=(const This_t& x)
-    {
-      if ( this != &const_cast<This_t &>(x) )
-        engine() = x.engine();
-      return *this;
-    }
-
   // Assign from an arbitrary type.
   // The engine should recognize if it is given a vector versus a scalar.
   template<class V>
@@ -269,23 +258,23 @@
   // Null ctor takes no action.
   VectorEngine()
   {
+    CTAssert(ElementProperties<T>::hasTrivialDefaultConstructor
+            && ElementProperties<T>::hasTrivialDestructor
+            && ElementProperties<T>::concrete);
+
     for (int i = 0; i < D; ++i)
       {
        ElementProperties<T>::construct(&x_m[i]);
       }
   }

-  // Copy ctor is deep.
-  inline VectorEngine(const VectorEngine<D,T,Full>&);
-
   // Copy from an argument of arbitrary type.
   // The arg must be indexable using VectorElem.
   template<class X>
-    inline VectorEngine(const X& x)
-      {
-        VectorAssign< VectorEngine<D,T,Full> , X , OpAssign, 0, D >
-          ::apply(*this,x,OpAssign());
-      }
+  inline VectorEngine(const X& x)
+  {
+    VectorAssign<This_t, X, OpAssign, 0, D>::apply(*this,x,OpAssign());
+  }

   // Construct from two or three scalars.
   template<class X1, class X2>
@@ -357,15 +346,6 @@
   //----------------------------------------------------------------------
   // Assignment

-  // Assign from the same kind of vector.
-  This_t&
-    operator=(const This_t& x)
-      {
-        if ( this != &x )
-          VectorAssign<This_t,This_t,OpAssign,0,D>::apply(*this,x,OpAssign());
-        return *this;
-      }
-
   // Assign from an arbitrary type.
   // The engine should recognize if it is given a vector versus a scalar.
   template<class V>
@@ -450,16 +430,6 @@
 };


-//----------------------------------------------------------------------
-// Copy ctor uses VectorAssign to copy the elements of x into this.
-//----------------------------------------------------------------------
-
-template<int D, class T>
-inline
-VectorEngine<D,T,Full>::VectorEngine(const VectorEngine<D,T,Full>& x)
-{
-  VectorAssign<This_t,This_t,OpAssign,0,D>::apply(*this,x,OpAssign());
-}

 #endif






reply via email to

[Prev in Thread] Current Thread [Next in Thread]