开发者

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.


  1. A function that takes two arguments and evaluates to a boolean is a "binary predicate" (likewise, "unary" for one argument, and "ternary" for three).

  2. In the second case, "deleter" seems to be an acceptable name (see boost::shared_ptr).


Surely there are no standards, common rules applies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜