std::pair<Url, std::string> UrlParser::parse()
{
return std::make_pair({ extract_scheme(), extract_hostname(), extract_port(),
extract_path(), extract_filename() }, host_ip_);
}
The host_ip_
variable is defined as
std::string host_ip_;
I get
UrlParser.cpp:91:64: error: no matching function for call to 'make_pair(<brace-enclosed initializer list>, std::string&)'
91 | extract_path(), extract_filename() }, host_ip_);
The problem is on the host_ip_
variable. If it's an std::string
, then what's the problem in returning it?
I found c++11 rvalue references in `std::make_pair` which explains that we can't call std::make_pair
with non-rvalue references, so I tried
std::make_pair({ extract_scheme(), extract_hostname(), extract_port(),
extract_path(), extract_filename() }, std::move(host_ip_));
but I get
error: no matching function for call to 'make_pair(<brace-enclosed initializer list>, std::remove_reference<std::__cxx11::basic_string<char>&>::type)'
91 | extract_path(), extract_filename() }, std::move(host_ip_));
By the way, why in the link provided, int
is an rvalue reference but const int
is not?