Skip to content

Instantly share code, notes, and snippets.

@foobit
Created February 28, 2014 00:09
Show Gist options
  • Select an option

  • Save foobit/9262501 to your computer and use it in GitHub Desktop.

Select an option

Save foobit/9262501 to your computer and use it in GitHub Desktop.

Revisions

  1. foobit created this gist Feb 28, 2014.
    12 changes: 12 additions & 0 deletions rvalue.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    std::vector<std::string>
    sorted(std::vector<std::string> names)
    {
    std::sort(names);
    return names;
    }

    // names is an lvalue; a copy is required so we don't modify names
    std::vector<std::string> sorted_names1 = sorted( names );

    // get_names() is an rvalue expression; we can omit the copy!
    std::vector<std::string> sorted_names2 = sorted( get_names() );