MTL_Object_Model [MTL Home] Programmers Guide
  Contents | Index |  Search 


Category:containers Component type:concept
Description
The object model for MTL is handle-based. This differs from the Standard Template Library. Object copies and assignment are shallow. This means that when you assign one vector object to another vector object you now have two handles to the same vector. The same applies to matrices. The example below shows how this works.

   dense1D x(5, 1.0);
   print_vector(x);
   > 1 1 1 1 1
   dense1D y = x;
   dense1D z(N);
   mtl::copy(x, z);
   x[2] = 3;
   print_vector(y);
   > 1 1 3 1 1
   print_vector(z);
   > 1 1 1 1 1
 

The vector y reflects the change made to vector x, since they are both handles to the same vector. Vector z, however, does not reflect the change in x, since it is a different vector.

The MTL algorithms assume that the vector and matrix objects you use are handle based. You'll notice that pass-by-value is used for the parameters. If you were to try to use an STL vector on its own in an MTL algorithm, the result vector would not be changed. The main reason that the handle based object model was used for MTL was that MTL makes heavy use of adapter helper functions to modify the arguments to MTL algorithms. The adapter functions return temporary objects. If the MTL algorithms use pass-by-reference for all their arguments then the C compiler will emit a warning. Using const pass-by-reference solves the problem for in parameters but not for out.

Even with this difference, the MTL makes considerable use of the STL containers. The implementations of the MTL OneD containers use STL containers (though we use our own higher performance version of the vector container). An example of the use of STL containers can be found in the sparse1D adapter, which can be used with the STL set, list, and vector containers.

The underlying STL objects within the MTL OneD containers are reference counted to make the memory management easier for the user. This is especially helpfull when the MTL matrix and vector object are used in the construction of larger object-oriented software systems.

Refinement of
Associated types
Concept Type name Description
Notations
Definitions
Expression semantics
Description Expression Semantics
Function specification
Name Function Complexity
Invariants
Models
Notes
See also

[MTL Home] Copyright © 1998,1999 University of Notre Dame. All Rights Reserved.