Skip to main content
12 events
when toggle format what by license comment
Feb 1, 2011 at 4:28 comment added Nav @Donotalo: I didn't suspect that '&' may be a problem. Will remember your cautionary note whenever I work with it though. Thanks :)
Jan 31, 2011 at 12:29 comment added Donotalo @Nav, yes. :) also the '&' may cause trouble depending on what you're doing with the state machine.
Jan 31, 2011 at 10:53 comment added Nav @Donotalo: Ok, you're referring to my use of 'const'? I agree with you then :)
Jan 31, 2011 at 10:06 comment added Donotalo @Nav: not this case. but consider this: en.wikipedia.org/wiki/Function_object#Maintaining_state
Jan 31, 2011 at 9:32 comment added Nav @Donotalo: I don't see how I'm using the function as a state machine. The function object isn't transitioning at any time.
Jan 31, 2011 at 7:39 comment added Donotalo @Nav: if you use the function object as state machine, your approach won't work.
Jan 31, 2011 at 6:35 comment added Nav Thanks. I figured the best way to have the parameters of sort_ints would have been void sort_ints(int* begin_items, int num_items, const ComparisonFunctor& c);
Jan 31, 2011 at 6:23 vote accept Nav
Jan 31, 2011 at 6:13 comment added templatetypedef @Nav- The compiler is usually really good at aggressively optimizing the receiver object out of the picture when invoking operator(). Coupled with the fact that the compiler can resolve which function is being called at compile-time (since it knows the type of the receiver), it's often much faster to use function objects than raw functions! (Though it does make the executable bigger)
Jan 31, 2011 at 6:01 comment added Tony Delroy @Nav: yes - a reference would be better. But, a comparison object rarely has much state, and is only passed once regardless of the number of items being sorted, so it's not likely to be a big deal.
Jan 31, 2011 at 5:55 comment added Nav Does that mean that the third parameter of sort_ints is actually taking an entire object by value? Won't that be bad/inefficient if we're working with large objects?
Jan 31, 2011 at 5:43 history answered templatetypedef CC BY-SA 2.5