Both GCC and Clang refuse to compile this one:
#include <string>
#include <utility>
using namespace std;
int main() {
const string s = "12345";
const string& r = s;
auto p = std::make_pair<string, string>(r, r);
}
GCC says:
error: cannot bind rvalue reference of type ‘std::__cxx11::basic_string<char>&&’ to lvalue of type ‘const std::string’ {aka ‘const std::__cxx11::basic_string<char>’}
While Clang says:
error: no matching function for call to 'make_pair'
Since I'm giving make_pair
explicit types, why doesn't it construct new strings from const string&
?
This one compiles:
auto p = std::make_pair<string, string>(string(r), string(r));