Difficulty with function objects
For this code I found on Wikipedia;
Code:
class compare_class { Code:
sort_ints(items, sizeof(items)/sizeof(items[0]), functor); I would've expected something like Code:
sort_ints(items, sizeof(items)/sizeof(items[0]), functor(items, sizeof(items)/sizeof(items[0]) )); Code:
bool operator()(int A, int B) |
Quote:
Quote:
That is only "automatic" if you consider sort_ints to be a black box, rather than part of your code. Consider this code: Code:
sort_ints( items, count, functor(x,y)); Contrast that with: Code:
sort_ints( items, count, functor); |
Though probably off-topic, but C++ standard claims functions are not objects, so the thread name is confusing.
|
Quote:
Or you can call it "Whoop-tee-doo" if you wish. But "Function Object" and "Functor" are names well known within the C++ community. |
Quote:
For a template to take both a functor and a function interchangeably, it should either assume that the argument is a pointer or it should use partial specialization to deduce whether it's a function pointer, a function reference, an object pointer, an object reference, or an object passed by value. In general, a function like this is used: Code:
template <class Type, class Function> You should also look at http://www.newty.de/fpt/index.html, previously function-pointer.org. Kevin Barry |
Quote:
|
thanks everyone! :)
|
All times are GMT -5. The time now is 07:52 PM. |