| 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 |