Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-01-12 13:49:03


On Fri, 12 Jan 2001, Dietmar Kuehl wrote:
dietma> Jeremy Siek wrote:
dietma>
dietma> > As for the one() and zero() functions, you'll see below I didn't use a
dietma> > traits function, but instead used a free function that takes an argument
dietma> > of the number type (the argument isn't really used, it just carries the
dietma> > type).
dietma>
dietma> Why would you want to pass an object then?
dietma>
dietma> template <typename X> X one();
dietma> template <> int one() { return 1; }
dietma>
dietma> int o = one<int>();
dietma>
dietma> OK, there may be compilers which don't accept this
dietma> standard code but why should I create a temporary
dietma> 20000x20000 matrix to get a unity matrix?

To do this efficiently, the unity matrix would not be the same type as the
matrix. It would not have any associated storage. However, the size of the
matrix is needed, which is what would be provided by the argument.

identity_matrix one(const matrix& A) {
  return identity_matrix(A.nrows(), A.ncols());
}

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk