Benjamin Lindley
Benjamin Lindley

Reputation: 103693

Template argument cannot be deduced

I'm trying to use std::transform to merge two equal size vectors into a vector of pairs.

int main()
{
    vector<string> names;
    // fill it with names    
    vector<int> nums;
    // fill it with numbers

    typedef pair<int,string> Pair_t;
    vector<Pair_t> pv;

    transform(nums.begin(), nums.end(),
              names.begin(), back_inserter(pv),
              make_pair<int,string>);
}

VC10 gives me:

'_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::back_insert_iterator<_Container>'
          with
          [
              _Container=std::vector<Pair_t>
          ]

So why can't the template argument be deduced? And how do I fix it?

Upvotes: 1

Views: 318

Answers (1)

kqnr
kqnr

Reputation: 3596

This is due to a bug in the current version of VC10 whereby the overload of make_pair cannot be resolved properly.

There is a discussion about this exact problem here, along with a workaround using a C++0x lambda expression, which is supported by VC10.

Upvotes: 5

Related Questions