Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!murtoa.cs.mu.oz.au!munnari.oz.au!comp.vuw.ac.nz!windy!srwmrbd
From: SRWMRBD@windy.dsir.govt.nz (ROBERT)
Newsgroups: comp.lang.c++
Subject: Re: named return values
Message-ID: <612@windy.dsir.govt.nz>
Date: 15 Aug 89 18:37:05 GMT
Organization: DSIR Wellington, NZ
Lines: 38

This is to support Doug Lea's proposal for "named return values". I
don't want to comment on the specific syntax he proposed - simply to say
we need a better way of getting objects back from functions.

I think this is more important for small objects than big ones where one
can use tricks to avoid the copying. For example I presume (I haven't
tested it) in a complex add that a significant amount of time (and
space) is used in the return.

For big objects like big matrices only the pointers and dimensional
information will need be copied at the end of a function or operation,
for functions or operations written by the library developer.

For example if you use my vector/matrix package (see my note of sometime
ago)

Matrix m1(100,100), m2(100,100), m3(100,100);

...

m1 = m1 + m2*2.0 + m3;

will create only one temporary which gets destroyed almost immediately
and does no copying of matrices. (At least it doesn't in Zortech; Doug
Lea found that AT&T C++ could generate extra initialises under some
circumstances).

However if you, a user, write a function  Matrix Sqrt(Matrix&)  then

m1 = Sqrt(m2);

will do one unnecessary copy. That is unless you know how to tell the
initialisation routines that the space occupied by the matrix you are
returning can be recycled.

So I want namded return values or the equivalent to make handling small
objects more efficient and make life simpler for people handling big
objects.