Questions tagged [mem-fun]

29 questions
11
votes
4 answers

some practical uses of mem_fn & bind

Can someone recommend some cool practical uses of tr1's mem_fn and bind utilities? I don't need esoteric c++ for library development. just some application level coding which makes uses of these. any help will be very appreciated.
Fanatic23
  • 3,378
  • 2
  • 28
  • 51
10
votes
4 answers

referencing a member function with bind1st and mem_fun

I have a C++ class where I'm trying to use std::bind1st to bind a member function to the 'this' parameter. For example: class MyClass { public: void Foo() { using namespace std; // this works fine this->Bar(); //…
PaulH
  • 7,759
  • 8
  • 66
  • 143
4
votes
2 answers

C++ forcing mem_fun to select a specific overloaded member function

I've actually figured out how to do what the title to my question suggests, but not in a satisfactory and portable way. Let me be more specific. This is a stripped down and modified version of my code: #include #include…
MPortilheiro
  • 128
  • 8
4
votes
1 answer

C++ To call member function in for_each for items in the member container

If I have a class (that mimic some of STL's container) like this: class Elem { public: void prepare(); // do something on *this // ... }; class Selector { public: typedef vector container_type; typedef container_type::iterator…
cinsk
  • 1,576
  • 2
  • 12
  • 14
4
votes
3 answers

storing mem_fun in a standard container

Is there a way to create a vector< mem_fun_t< ReturnType, MyClass > > ? The error i'm seeing is: error C2512: 'std::mem_fun1_t<_Result,_Ty,_Arg>' : no appropriate default constructor available
Vargas
  • 2,125
  • 2
  • 33
  • 53
3
votes
4 answers

How to assign method member pointer of a subclass?

My problem is a bit complicated. I have one class (e: Component) which have Ports objects. When a Component create a Port object, it pass one of its methods to the Port constructor. Methods signatures : typedef std::vector
Neozaru
  • 1,109
  • 1
  • 10
  • 25
3
votes
1 answer

Can I use boost::bind() with mem_fun_ref()?

My question is pretty straightforward: can I do something like this? Say class foo contains the following member function: foo foo::DoSomething(input_type1 input1, input_type2 input2) { ... // Adjust private datamembers return…
Wouter
  • 161
  • 1
  • 6
2
votes
4 answers

STL for_each complaining about argument list

As part of a homework assignment, we are supposed to map the occurrence of each character in a map. Our function is supposed to use std::for_each and pass in the character to be evaluated. My function is: std::for_each(document_.begin(), …
IAE
  • 2,213
  • 13
  • 37
  • 71
2
votes
3 answers

How do I use std::tr1::mem_fun in Visual Studio 2008 SP1?

The VS2008 SP1 documentation talks about std::tr1::mem_fun. So why, when I try and use std::tr1::mem_fun, why do I get this compile error?: 'mem_fun' : is not a member of 'std::tr1' At the same time, I can use std::tr1::function without…
mackenir
  • 10,801
  • 16
  • 68
  • 100
2
votes
5 answers

How to have memfun with two parameters

I want to use this function "EnumWindows(EnumWindowsProc, NULL);". The EnumWindowsProc is a Callback function: BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam); For this callback I want to use a member function of a class. e.g: Class…
Jaguar
  • 339
  • 2
  • 3
  • 9
2
votes
2 answers

mem_fun and bind1st problem

I've following class: class A { public: // ctr and etc ... A* clone(B* container); }; Now, I've a vector availableObjs populated already. I want to call clone on each of those, so and insert cloned objects into a new container clonedObjs of…
soumeng78
  • 600
  • 7
  • 12
1
vote
1 answer

void troubles return value to string

Based on this article, I tried to create a generic parser, which outputs the return value of the called function as a string. Parsing std::vector of std::strings into std::tuple of arbitrary types Unfortunately, I didn't figure out, how to format…
PirklW
  • 484
  • 2
  • 16
1
vote
2 answers

Using std::vector::push_back with std::mem_fun and std::bind1st

I'm trying to use std::vector::push_back with std::mem_fun and std::binder1st, but it doesnt seem to be feasible, can this be done? I've tried to exemplify with the code below. #include #include #include using…
Vargas
  • 2,125
  • 2
  • 33
  • 53
1
vote
2 answers

C++: Creating a function object with mem_fn and bind1st

Disclaimer: This description contains a lot of Qt specific functionality. This is not necessary to answer the question, I'm just including it to explain the background. I need to do some heavy computations in my QT application. In order to do this,…
lhk
  • 27,458
  • 30
  • 122
  • 201
1
vote
1 answer

Must I use boost::bind to create polymorphic "transform" functionality?

I am trying to call a member function on each object in a vector, with a specified parameter, and I would like the call to be polymorphic. I believe the function vstuff shown below achieves this. But can vstuff be modified to take a vector<…
imateapot
  • 141
  • 1
  • 1
  • 8
1
2