C++函数对象术语 functor、deltor、comparator 等

发布于 2024-09-05 19:26:45 字数 578 浏览 2 评论 0 原文

常见函子的各种类型是否有一个普遍接受的术语?

例如,我发现自己很自然地使用比较器来进行比较函子,如下所示:

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;
    }
};

或者使用术语 deltor 来表示如下内容:

struct DeleteAddrInfo { 
    void operator()(const addr_map_t::value_type &pr) const {
        freeaddrinfo(pr.second);
    }
};

如果使用这些类型的速记术语很常见,那么某个地方是否有所有这些术语的字典?

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 &pr) const {
        freeaddrinfo(pr.second);
    }
};

If using these kinds of shorthand terms is common, it there some dictionary of them all someplace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乱了心跳 2024-09-12 19:26:45

比较器的使用相当广泛,在 Java 中比在 C++ 中更是如此 - 比较函数是原始 STL 中的术语,比较器是 Java API 中的术语。

“deltor”不是一个常用的词,听起来像“delta”,所以不会让我想到释放指针的东西。

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.

万水千山粽是情ミ 2024-09-12 19:26:45
  1. 接受两个参数并计算为布尔值的函数是“二元谓词” (同样,“一元”表示一个参数,“三元”表示三个)。

  2. 在第二种情况下,“deleter”似乎是一个可接受的名称(请参阅boost::shared_ptr)。

  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).

油饼 2024-09-12 19:26:45

当然没有标准,通用规则适用。

Surely there are no standards, common rules applies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文