Open up Visual Studio 2010 and create a C++ project using the Win32 Console Application wizard. Then, enter the following code in your main .cpp file:
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> a;
vector<string> b;
map<string, string> c;
// Populate vectors
transform(a.begin(), a.end(), b.begin(), inserter(c, c.begin()), make_pair<string, string>);
return 0;
}
Finally, attempt to compile this program.
The compiler fails with the following error sequence:
1>------ Build started: Project: Test Vector To Map, Configuration: Debug Win32 ------
1> Test Vector To Map.cpp
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_InTy (&)[_InSize]' from 'std::_Vector_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1293) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InIt2,_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_OutTy (&)[_OutSize]' from 'std::insert_iterator<_Container>'
1> with
1> [
1> _Container=std::map<std::string,std::string>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1279) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutIt,_Fn2)' : could not deduce template argument for '_InTy (&)[_InSize]' from 'std::_Vector_iterator<_Myvec>'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1267) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2914: 'std::transform' : cannot deduce template argument as function argument is ambiguous
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::insert_iterator<_Container>'
1> with
1> [
1> _Container=std::map<std::string,std::string>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1249) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2780: '_OutTy *std::transform(_InIt,_InIt,_OutTy (&)[_OutSize],_Fn1)' : expects 4 arguments - 5 provided
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1127) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2780: '_OutIt std::transform(_InIt,_InIt,_OutIt,_Fn1)' : expects 4 arguments - 5 provided
1> c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1111) : see declaration of 'std::transform'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The compiler should match the std::transform template against the definition:
template<class _InIt1,
class _InIt2,
class _OutIt,
class _Fn2> inline
_OutIt transform(_InIt1 _First1, _InIt1 _Last1,
_InIt2 _First2, _OutIt _Dest, _Fn2 _Func);