1

Sometimes I see function declare like this:

void foo(vector<some type>&& inputs);

What is the major reason to use && instead of &?

WhatABeautifulWorld
  • 3,198
  • 3
  • 22
  • 30
  • 4
    Probably the two most common major reasons are to allow move semantics and perfect forwarding. – Jerry Coffin Mar 04 '13 at 05:20
  • @Ben, yes, it does indeed look like a duplicate. I think my answer's better than that thread's answer though! – Dave Mar 04 '13 at 05:23

1 Answers1

3

This is a new thing in C++11 called rvalue references.

You can read a great introduction to them here: http://thbecker.net/articles/rvalue_references/section_01.html

Essentially, it says it will be a reference to an object which can be destroyed without causing problems, and is used to optimise certain operations such as copy constructors (which can be changed for a swap if the other object can be destroyed).

Dave
  • 44,275
  • 12
  • 65
  • 105