Can std::hash be used to hash function pointers?

前端 未结 3 853
执笔经年
执笔经年 2021-01-03 22:56

Can the C++11 std::hash type be used to hash function pointers? There is a hash partial specialization defined as

template 

        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 23:54

    I found the following:

    17.6.3.4 Hash requirements

    A type H meets the Hash requirements if:

    • it is a function object type (20.8)

    [...]

    And then, the referenced 20.8 states:

    A function object type is an object type (3.9) that can be the type of the postfix-expression in a function call (5.2.2, 13.3.1.1).228 A function object is an object of a function object type. In the places where one would expect to pass a pointer to a function to an algorithmic template (Clause 25), the interface is specified to accept a function object. This not only makes algorithmic templates work with pointers to functions, but also enables them to work with arbitrary function objects.

    It kind of states it backwards... but the statement not only makes algorithmic templates work with pointers to functions... seems appropriate for your question.

提交回复
热议问题