[LC++]Using the "return value optimization"

Mark Phillips mark at austrics.com.au
Mon Aug 13 18:28:04 UTC 2001


Suppose I have a function

  void doSomething(int& i, int const& parameter);

and suppose I have a class with:

  class someClassTy {
  ...
  public:
    uint operator()(int const& parameter) {
      int temp;
      doSomething(temp, parameter);
      return temp;
    }  
  ...
  }

Now the only problem with the above is that I don't think
it makes use of the "return value optimization".  To get
this to work, you would need some kind of syntax that
allows an integer to be initialized using a function.  Ie
something like:

      return int(doSomething(***here***, parameter));

Unfortunately no such syntax exists (to my knowledge).  Is
there any way around my problem?

Thanks,

Mark.



More information about the tuxCPProgramming mailing list