Path: utzoo!attcan!uunet!husc6!uwvax!umn-d-ub!nic.MR.NET!hal!cwjcc!tut.cis.ohio-state.edu!osu-cis!att!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.lang.c++ Subject: Re: Continuing efforts to build a CM++ (sic) environment (long) ... Summary: a technique Keywords: compile time attributes, expressions, operators, temporaries Message-ID: <8415@alice.UUCP> Date: 11 Nov 88 17:45:29 GMT References: <17796@shemp.CS.UCLA.EDU> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 29 Giving control to the (library) programmer to the point of controlling temporary variable usage is non-trivial. However, there are ways of using C++ so that temporaries isn't user. Assume a class Matrix for which creation/copying/destruction is so expensive that you'd rather not have temporary variables introduced: f() { Matrix a,b,c; // ... a = b + c; // yuck: temporary used a = a * c; // yuck: temporary used } however: f() { Matrix b,c; // ... Matrix a = b + c; // temporary not used a *= c; // temporary not used } Initialization is typically cheaper than assignment (since the compiler doesn't need to introduce a temporary to protect against aliasing) and *=, +=, etc. is almost always a win for user-defined types.