C++ function object terminology functor, deltor, comparator, etc
Is there a commonly accepted terminology for various types for common functors?
For instance I found myself naturally using comparator for comparison functors like this:
struct ciLessLibC : public std::binary_function<std::string, std::string, bool> {
bool operator()(const std::string &lhs, const std::string &rhs) const {
return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
}
};
Or using the term deltor for something like this:
struct DeleteAddrInfo {
void operator()(const addr_map_t::value_type &a开发者_如何学运维mp;pr) const {
freeaddrinfo(pr.second);
}
};
If using these kinds of shorthand terms is common, it there some dictionary of them all someplace?
Comparator is fairly widely used, more so in Java than C++ - comparison function being the terminology in the original STL, Comparator the terminology in the Java API.
'deltor' isn't a word in common use, and sounds like 'delta', so wouldn't make me think of something which frees pointers.
A function that takes two arguments and evaluates to a boolean is a "binary predicate" (likewise, "unary" for one argument, and "ternary" for three).
In the second case, "deleter" seems to be an acceptable name (see boost::shared_ptr).
Surely there are no standards, common rules applies.
精彩评论