Connecting Tech Pros Worldwide Forums | Help | Site Map

can not reference make_pair?

John Black
Guest
 
Posts: n/a
#1: Jul 22 '05
Hi,
I have this code piece,

vector<int> v1, v2;
vector<pair<int, int> > uups;
....

transform(v1.begin(), v1.end(), v2.begin(), uups.end(),
ptr_fun(make_pair));

But my gcc compiler complains that "no matching function for call to
`ptr_fun(<unknown type>". Do you know what's wrong here?

Thanks.

Jonathan Turkanis
Guest
 
Posts: n/a
#2: Jul 22 '05

re: can not reference make_pair?



"John Black" <black@eed.com> wrote in message
news:cne57b$iv83@cliff.xsj.xilinx.com...[color=blue]
> Hi,
> I have this code piece,
>
> vector<int> v1, v2;
> vector<pair<int, int> > uups;
> ....
>
> transform(v1.begin(), v1.end(), v2.begin(), uups.end(),
> ptr_fun(make_pair));[/color]

std::make_pair is a function template; to retrieve a function pointer to one of
its specializations you must use a cast or assign it to a function pointer
variable, as in the following:

#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

using namespace std;

int main()
{
pair<int, int> (*make_int_pair) (int, int) = make_pair;

vector<int> v1, v2;
vector<pair<int, int> > uups;
transform(v1.begin(), v1.end(), v2.begin(), uups.end(),
ptr_fun(make_int_pair));
}

One more thing: I'm not sure the standard guarantees that make_pair doesn't have
additional function parameters with default values. Probably someone else here
knows.
[color=blue]
> Thanks.[/color]

Jonathan


ES Kim
Guest
 
Posts: n/a
#3: Jul 22 '05

re: can not reference make_pair?


"John Black" <black@eed.com> wrote in message
news:cne57b$iv83@cliff.xsj.xilinx.com...[color=blue]
> Hi,
> I have this code piece,
>
> vector<int> v1, v2;
> vector<pair<int, int> > uups;
> ....
>
> transform(v1.begin(), v1.end(), v2.begin(), uups.end(),
> ptr_fun(make_pair));
>
> But my gcc compiler complains that "no matching function for call to
> `ptr_fun(<unknown type>". Do you know what's wrong here?
>
> Thanks.[/color]

make_pair is not a function, just a template. But make_pair<int, int> is.
One more thing: you must "push_back" the result into uups, not just
placing it at the end.

transform(v1.begin(), v1.end(), v2.begin(), back_inserter(uups),
ptr_fun(make_pair<int, int>));

--
ES Kim


Closed Thread