Skip to content

Instantly share code, notes, and snippets.

@sftrabbit
Created January 28, 2014 11:02
Show Gist options
  • Save sftrabbit/8665717 to your computer and use it in GitHub Desktop.
Save sftrabbit/8665717 to your computer and use it in GitHub Desktop.
C++ Reference Binding
#include <iostream>
#include <string>
std::string modifiable_rvalue() {
return "foo";
}
const std::string const_rvalue() {
return "bar";
}
int main() {
std::string modifiable_lvalue("baz");
const std::string const_lvalue("qux");
std::string& a = modifiable_lvalue;
//std::string& b = const_lvalue; // ERROR
//std::string& c = modifiable_rvalue(); // ERROR
//std::string& d = const_rvalue(); // ERROR
const std::string& e = modifiable_lvalue;
const std::string& f = const_lvalue;
const std::string& g = modifiable_rvalue();
const std::string& h = const_rvalue();
//std::string&& i = modifiable_lvalue; // ERROR
//std::string&& j = const_lvalue; // ERROR
std::string&& k = modifiable_rvalue();
//std::string&& l = const_rvalue(); // ERROR
//const std::string&& m = modifiable_lvalue; // ERROR
//const std::string&& n = const_lvalue; // ERROR
const std::string&& o = modifiable_rvalue();
const std::string&& p = const_rvalue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment