Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Error compiling std::make_pair

Michael_M_19
Beginner
938 Views

Hi Folks,

This code fair to compile with -std=c++11 but compiles fine without the -std=c++11 switch.

#include <string>
#include <iostream>
#include <utility>
int main(int argc, char* argv[])
{
  std::pair<int, std::string> apair=std::make_pair <int, std::string> ( 66, "sixty-six" );
}

error:/home/michael/programming/compilers/intel/bin/icpc -std=c++11 tt.cpp
tt.cpp(6): error: no instance of function template "std::make_pair" matches the argument list
            argument types are: (int, const char [10])
    std::pair<int, std::string> apair=std::make_pair <int, std::string> ( 66, "sixty-six" );

/home/michael/programming/compilers/intel/bin/icpc -v
icpc version 14.0.0 (gcc version 4.8.0 compatibility)

g++ --version                                                                                                                  
g++ (GCC) 4.8.1 20130603 (Red Hat 4.8.1-1)        

This is on Fedora 19 X64

Enjoy

michael

0 Kudos
4 Replies
TimP
Honored Contributor III
938 Views

I got the same complaint, regardless of -std=c++11, with several versions of g++,  I think icpc is more strict about matching std::string against const char[], without an appropriate cast.  Earlier versions of icpc don't get along at all with the latest g++.

It might be interesting to see whether is_convertible shows the same differences between g++ and icpc.  But I don't have such a personal interest in language lawyering, in case that's what you mean by "Enjoy!".

0 Kudos
Michael_M_19
Beginner
938 Views

well Im definitly not a language lawyer but..

the code in the message above compiles with clang 3.3, clang trunk and g++ on fedora and msvc 2012 on windows.

Also this small variant compiles fine with icpc in c++11 mode

#include <string>
#include <iostream>
#include <utility>
int main(int argc, char* argv[])
{
  std::string s("sixty six");
  std::pair<int, std::string> apair=std::make_pair <int, std::string> ( 66, s.c_str() );
}

michael

0 Kudos
Melanie_B_Intel
Employee
938 Views

I tried your test case with the newest 14.0 compiler which I could find (14.0.4) and it compiles ok with or without the -std=c++11, looks like that problem was fixed.  We're currently shipping 16.0

0 Kudos
Kittur_G_Intel
Employee
938 Views

That's correct Melanie. I tried with the next 14.0 version (update release) and it works fine. 

@Michael:  If you can upgrade to the latest 16.0 release (Initial Release) that'll be nice since a lot of new features/bug fixes etc., has gone into the newer release as well...

_Kittur

0 Kudos
Reply