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> > 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> Why would you want to pass an object then?
dietma> template <typename X> X one();
dietma> template <> int one() { return 1; }
dietma> int o = one<int>();
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:
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906

Boost list run by bdawes at, gregod at, cpdaniel at, john at