Why is std::hash a struct instead of a function?

前端 未结 2 1236
南笙
南笙 2020-12-25 15:21

Standard library implements std::hash as a template struct that is specialized for different types. It is used like this:

#include 
#include          


        
2条回答
  •  我在风中等你
    2020-12-25 15:48

    A template function can not be partially specialized for types, while std::hash specialized for different types as a class template.

    And, in this template class based way, you can do some meta programming such as accessing to return type and key type like below:

    std::hash::argument_type
    std::hash::result_type
    

提交回复
热议问题