A more general question is suggested here . Consider this as an extension to this.
I understand that classes represent the type of objects, and we must use nouns as their names. But there are function objects supported in many languages ββthat act more as functions than objects. Should I call these classes also nouns, or are verbs approved in this case. doSomething(), semantically, makes more sense than Something().
doSomething()
Something()
Update / Conclusion
The two top voices I received share a mixed opinion:
AttilaHowever, in the case of functors, they represent an βaction,β so assigning them a verb (or some combination of nouns-verbs) is more appropriate - just as you would call a function based on what it does.rookAn instance of a functor, on the other hand, is actually a function, and might be better named accordingly. Following Jim's suggestion above,SomethingDoer doSomething; doSomething();
Attila
However, in the case of functors, they represent an βaction,β so assigning them a verb (or some combination of nouns-verbs) is more appropriate - just as you would call a function based on what it does.
rook
An instance of a functor, on the other hand, is actually a function, and might be better named accordingly. Following Jim's suggestion above,SomethingDoer doSomething; doSomething();
SomethingDoer doSomething; doSomething();
Both of them, having passed some code, seem to be common practice. The GNU implementation stl I found the classes such as negate, plus, minus(BITS / stl_function.h), etc. And variate_generator, mersenne_twister(tr1 / random.h). Similarly, in the boost I found the classes such as base_visitor, predecessor_recorder(graph / visitors.hpp), as well as inverse, inplace_erase(icl / functors.hpp)
negate
plus
minus
variate_generator
mersenne_twister
base_visitor
predecessor_recorder
inverse
inplace_erase
(, , ) "", . "", ( -) - , , , .
, (, ..) , , /.
( , "" ) . ( , "" ) , , , "" ( ).
, , , , , (, ++). , (.. , operator(), command.do()), / , .
operator()
command.do()
- , (, ), . , , , , . , SomethingDoer doSomething; doSomething();
, , , , ... Filter Show . .
Filter
Show
Function, Callback, Action, Command .., SortFunction, SearchAction, ExecuteCommand Sort, Search, Execute, .
Function
Callback
Action
Command
SortFunction
SearchAction
ExecuteCommand
Sort
Search
Execute
I think there are two ways to see this:
1) A class that can be reasonably called so that it can be called as a functor directly during construction:
Doer()(); // constructed and invoked in one shot, compiler could optimize
2) An instance in cases where we want the functor to be called several times in an object-object without a name, or, perhaps, for stylistic reasons when syntax C # 1 is not preferable.
Doer _do; _do(); // operator () invocation after construction
I like the @Rook sentence above to designate a class with words that have the same form of a verb and a noun, such as Searchor Filter.