C++函数对象术语 functor、deltor、comparator 等
常见函子的各种类型是否有一个普遍接受的术语?
例如,我发现自己很自然地使用比较器来进行比较函子,如下所示:
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);
}
};
如果使用这些类型的速记术语很常见,那么某个地方是否有所有这些术语的字典?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
比较器的使用相当广泛,在 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.
接受两个参数并计算为布尔值的函数是“二元谓词” (同样,“一元”表示一个参数,“三元”表示三个)。
在第二种情况下,“deleter”似乎是一个可接受的名称(请参阅boost::shared_ptr)。
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.