为什么std :: binary_function< ...>没有一个operator()方法? [英] Why does std::binary_function<...> not have an operator() method?
问题描述
我注意到 std :: binary_function< ...>
只是一个带有typedef的结构体。在链接,它具体说:
I noticed that std::binary_function<...>
is only a struct with typedefs. At the link, it specifically says:
binary_function未定义
operator()
;预期派生类将定义这个。
binary_function does not define
operator()
; it is expected that derived classes will define this.
这对我来说似乎没有意义。如果你可以继承它,或者实例化它,没有一个函数,这个类(或结构)的要点是什么?
This seems nonsensical to me. What's the point of this class (or struct) if you can inherit it, or instantiate it, without having a function at all? Or are the semantics different than they seem to me?
推荐答案
请记住,C ++ 11已弃用,C ++ 17将删除 binary_function
。
Remember that C++11 deprecated and C++17 removes binary_function
.
binary_function
由(现在已弃用)函数适配器使用的typedef,例如 not2
。记住,在 auto
和 decltype
可用之前,很难或不可能推导出这些类型,因此必须提供手动。另外,定义 operator()
的意义是什么?没有可能的实现,使得纯虚拟
将是一个显着的性能下降。
binary_function
was simply a helper to create the typedefs used by the (also now deprecated) function adapters, e.g. not2
. Remember that before auto
and decltype
were available it was hard or impossible to deduced those types, so they had to be provided manually. Also, what would be the point of defining operator()
? There could not be a possible implementation and making it pure virtual
would be a significant performance drain.
这篇关于为什么std :: binary_function< ...>没有一个operator()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!