0

I am trying to write a function for parsing a config.ini file but I've come across this error I've not really come across before

'std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::basic_string<char,std::char_traits<char>,std::allocator<char>>> std::make_pair<std::string,std::string>(_Ty1 &&,_Ty2 &&)': cannot convert argument 1 from 'std::string' to 'std::string &&'

My code looks like this:

std::map<std::string, std::string> Iasynth::getConfigOptions(std::string const & configData)
{
std::map<std::string, std::string> result;
std::istringstream iss(configData);
bool key = true;
std::string keyData;
std::string valueData;

for (std::string token; std::getline(iss, token, '\n'); )
{
    for (std::string token; std::getline(iss, token, '='); )
    {
        if (key)
        {
            keyData = std::move(token);
            key = false;
        }
        else
        {
            valueData = std::move(token);
            result.insert(std::make_pair<std::string, std::string>(keyData, valueData));
            key = true;
        }
    }
}

return result;
}
Richie
  • 364
  • 3
  • 8
  • 20
  • 1
    You have to let deduction of `make_pair` -> `make_pair(keyData, valueData)`. – Jarod42 May 17 '18 at 23:53
  • 1
    Or even don't use it at all: `result.emplace(keyData, valueData);`. – Jarod42 May 17 '18 at 23:54
  • 1
    The entire point of `make_pair` is that you don't need to give the template arguments. If you really want to be particular about the type of the pair, just do `std::pair(keyData, valueData)`. But the `emplace` comment above is probably the best approach. – aschepler May 18 '18 at 00:26

0 Answers0