Advertisement
homer512

Move const ref

Feb 9th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <utility>
  2. // using std::move
  3. #include <string>
  4. // using std::string
  5. #include <cstdio>
  6. // using std::printf
  7.  
  8. namespace {
  9. #  ifdef WITH_CONST_RREF
  10.     void print(const std::string&& str)
  11.     {
  12.         std::printf("Copy const rref %s\n", str.c_str());
  13.     }
  14. #  endif /* WITH_CONST_RREF */
  15.     void print(const std::string& str)
  16.     {
  17.         std::printf("Copy %s\n", str.c_str());
  18.     }
  19.     void print(std::string&& str)
  20.     {
  21.         std::printf("Move %s\n", str.c_str());
  22.     }
  23.     void move_to_print(const std::string& str)
  24.     {
  25.         print(std::move(str));
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.     std::string foo("foo");
  32.     move_to_print(foo);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement