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. 2 2323
"John Black" <bl***@eed.com> wrote in message
news:cn*********@cliff.xsj.xilinx.com... 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));
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.
Thanks.
Jonathan
"John Black" <bl***@eed.com> wrote in message
news:cn*********@cliff.xsj.xilinx.com... 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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JustSomeGuy |
last post by:
in the stl map class I see the use of a function pair and make_pair.
What is the difference between pair and make_pair?
dictionary.insert(std::pair<Key, Value>(k,v));
works as well as:
...
|
by: lallous |
last post by:
Hello
Given this:
map<int, mystruct> m;
m = item;
item.id++;
m = item;
How can I get a direct refrence to the location of the just inserted item?
|
by: Jim Langston |
last post by:
Expected output of program:
Key is: 0 String is: Hello
Key is: 1 String is: Goodbye
Key is: 2 String is: The end
Actual output:
Key is: 0 String is: The End
Key is: 1 String is:
Key is: 2...
|
by: Markus Dehmann |
last post by:
I am trying to make a pair with a string and an auto_ptr:
#include <iostream>
#include <map>
using namespace std;
int main(){
auto_ptr<intp(new int(3));
make_pair("x",p);
}
|
by: Michael Holm |
last post by:
Calling the function
"float dist = Splines.Pick(Vector2(x,y), 5.0f, type, &point);"
The function is now defined as
float BSpline::Pick(Vector2Coord, float radius, ePickType &type, Vector3...
|
by: Juha Nieminen |
last post by:
Is there any online C++ library reference containing all the functions
and types in the standard C++ library? A quick google search gives C++
references alright, but they all seem to be quite...
|
by: subramanian100in |
last post by:
Given two types T1 and T2, we can create
pair<T1, T2p(value1, value2);
where value1 and value2 are of types T1 and T2 respectively.
Suppose we want to assign a new pair<value to p. We can do...
|
by: puzzlecracker |
last post by:
Does map copy the object, both key and value during the insert?
is this example correct:
std::map<std::string Tmy_map;
template<typename T>
void foo(const std::string str, const T & t){...
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |