Click here to Skip to main content
16,007,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: View Class information Pin
Dave Bryant11-Nov-02 13:22
Dave Bryant11-Nov-02 13:22 
GeneralShellExecute / Multi-Instances Pin
JoeSox11-Nov-02 10:10
JoeSox11-Nov-02 10:10 
GeneralRe: ShellExecute / Multi-Instances Pin
dabs11-Nov-02 11:06
dabs11-Nov-02 11:06 
GeneralRe: ShellExecute / Multi-Instances Pin
JoeSox12-Nov-02 3:58
JoeSox12-Nov-02 3:58 
GeneralDesign Recommendation. Warning - long-g-g. Pin
11-Nov-02 9:43
suss11-Nov-02 9:43 
QuestionWhich font is it using? Pin
ed987111-Nov-02 9:26
ed987111-Nov-02 9:26 
AnswerRe: Which font is it using? Pin
Dave Bryant11-Nov-02 9:57
Dave Bryant11-Nov-02 9:57 
GeneralSTL rambling... Function object adaptors .. Pin
Maximilien11-Nov-02 9:21
Maximilien11-Nov-02 9:21 
After looking at Jörgen Sigvardsson's implementation of the Observer pattern, I have a couple of questions about a few STL thingy that he uses :

struct IObserver {
 virtual void OnNotify(class Observable* pObservable) = 0;
};
...
// in a class declaration
void Notify() 
{
 std::for_each( setObservers.begin(),
                setObservers.end(),
                std::bind2nd(std::mem_fun1(&IObserver::OnNotify), this));
}
...


which goes like this ( since it's working! ):

Call the OnNotify method on each iterator of the set setObserver with the this parameter, where it can be of the class IObserver or be inherited from it.
and will translate to something like <pseudo code="">:
for ( it = begin; it < end ++it )
{
it->OnNotify( this );
}

now, to the specific ( and from what I understand ( or not ) from STL's documentation )

std::mem_fun1 : this creates (adapt) a simple function call from the argument ( even if it's not a static function), mem_fun1 will generate a function without a parameter ( in that case ).

std::bind2nd : this will "add" a parameter to the mem_fun1 generated function ?! this is where I got lost ... at least more lost than before ....
I don't quite understand the definition given on SGI's STL pages :

"Binder2nd is a function object adaptor: it is used to transform an adaptable binary function into an adaptable unary function."

Why would I adapt a function from having 2 parameters ( binary ) to 1 parameter ( unary ) ? Or Am I reading this the other way around ? and the bind2nd will add the iterator to be passed to the for_each ?


Why use the binder and mem_fun functions while it can be done with a simple for loop

Max.
GeneralRe: STL rambling... Function object adaptors .. Pin
Daniel Turini11-Nov-02 9:42
Daniel Turini11-Nov-02 9:42 
GeneralRe: STL rambling... Function object adaptors .. Pin
Maximilien11-Nov-02 10:02
Maximilien11-Nov-02 10:02 
GeneralRe: STL rambling... Function object adaptors .. Pin
peterchen11-Nov-02 9:50
peterchen11-Nov-02 9:50 
GeneralRe: STL rambling... Function object adaptors .. Pin
Tim Smith11-Nov-02 10:03
Tim Smith11-Nov-02 10:03 
GeneralRe: STL rambling... Function object adaptors .. Pin
peterchen11-Nov-02 14:07
peterchen11-Nov-02 14:07 
Questionattaching my own menu bar?? Pin
pnpfriend11-Nov-02 8:52
pnpfriend11-Nov-02 8:52 
AnswerRe: attaching my own menu bar?? Pin
Mash11-Nov-02 10:30
Mash11-Nov-02 10:30 
GeneralRe: attaching my own menu bar?? Pin
pnpfriend11-Nov-02 11:03
pnpfriend11-Nov-02 11:03 
GeneralRe: attaching my own menu bar?? Pin
Mash11-Nov-02 12:07
Mash11-Nov-02 12:07 
GeneralRe: attaching my own menu bar?? Pin
pnpfriend12-Nov-02 8:33
pnpfriend12-Nov-02 8:33 
QuestionItem Selection Notification? Pin
Mash11-Nov-02 8:50
Mash11-Nov-02 8:50 
GeneralDialog Resize Pin
SavageBeast11-Nov-02 8:12
SavageBeast11-Nov-02 8:12 
GeneralRe: Dialog Resize Pin
Anonymous11-Nov-02 8:30
Anonymous11-Nov-02 8:30 
GeneralWorkspace name Pin
meirav11-Nov-02 8:06
meirav11-Nov-02 8:06 
GeneralRe: Workspace name Pin
SavageBeast11-Nov-02 8:14
SavageBeast11-Nov-02 8:14 
GeneralRe: Workspace name Pin
beetung11-Nov-02 8:24
beetung11-Nov-02 8:24 
GeneralCStatic center vert with wordbreak Pin
Dave_11-Nov-02 7:46
Dave_11-Nov-02 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.