can not reference make_pair?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Black

    can not reference make_pair?

    Hi,
    I have this code piece,

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

    transform(v1.be gin(), v1.end(), v2.begin(), uups.end(),
    ptr_fun(make_pa ir));

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

    Thanks.
  • Jonathan Turkanis

    #2
    Re: can not reference make_pair?


    "John Black" <black@eed.co m> wrote in message
    news:cne57b$iv8 3@cliff.xsj.xil inx.com...[color=blue]
    > Hi,
    > I have this code piece,
    >
    > vector<int> v1, v2;
    > vector<pair<int , int> > uups;
    > ....
    >
    > transform(v1.be gin(), v1.end(), v2.begin(), uups.end(),
    > ptr_fun(make_pa ir));[/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.be gin(), v1.end(), v2.begin(), uups.end(),
    ptr_fun(make_in t_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


    Comment

    • ES Kim

      #3
      Re: can not reference make_pair?

      "John Black" <black@eed.co m> wrote in message
      news:cne57b$iv8 3@cliff.xsj.xil inx.com...[color=blue]
      > Hi,
      > I have this code piece,
      >
      > vector<int> v1, v2;
      > vector<pair<int , int> > uups;
      > ....
      >
      > transform(v1.be gin(), v1.end(), v2.begin(), uups.end(),
      > ptr_fun(make_pa ir));
      >
      > But my gcc compiler complains that "no matching function for call to
      > `ptr_fun(<unkno wn 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.be gin(), v1.end(), v2.begin(), back_inserter(u ups),
      ptr_fun(make_pa ir<int, int>));

      --
      ES Kim


      Comment

      Working...