[cpp-threads] RE: "Agenda" for august 23-25 concurrency meeting

Nick Maclaren nmm1 at cus.cam.ac.uk
Thu Aug 31 18:28:51 BST 2006


Howard Hinnant <hinnant at twcny.rr.com> wrote:
> 
> In C++03, functional programming is not without fear, worry, and/or  
> guilt.  E.g. I need to compute a vector<int> and return it to the  client.  How should I do that?

A very good question.

> Today's advice is to pass an empty vector to your function by  
> reference, out of fear that if you were to return it by value, RVO  
> will not kick in:
> 
>      void compute(vector<int>& v, input data);  // guaranteed efficient
> 
> vs:
> 
>      vector<int> compute(input data);  // is this ridiculously  
> expensive?

Well, it may be.  And so may the first be.  You are thinking heaps;
if the implementor is thinking (Algol 68 style) stacks, you have just
done precisely the wrong thing.

>            *** Move semantics enables guilt-free functional  
> programming. ***

I am afraid not.  That is true only if the implementor is also thinking
the same way.

Now, the people who have most experience here are the Fortran 90/95/2003
brigade.  I am not fully in touch with the details, as most of the real
Fortran 90 programmers here needed little help with Fortran, and I spent
most time on Fortran 77 style code, libraries etc.  But their experience
is VERY relevant.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list