This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD Concepts status.

### 1072. Is `std::hash` a constrained template or not?

Section: 20.14.19 [unord.hash] Status: NAD Concepts Submitter: Alisdair Meredith Opened: 2009-03-19 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [unord.hash].

View all issues with NAD Concepts status.

Discussion:

Is `std::hash` a constrained template or not?

According to class template `hash` 20.14.19 [unord.hash], the definition is:

>     template <class T>
>     struct hash : public std::unary_function<T, std::size_t> {
>       std::size_t operator()(T val) const;
>     };

And so unconstrained.

According to the `<functional>` synopsis in p2 Function objects 20.14 [function.objects] the template is declared as:

>     template <ReferentType T> struct hash;

which would make hash a constrained template.

[ 2009-03-22 Daniel provided wording. ]

[ Batavia (2009-05): ]

> Alisdair is not certain that Daniel's proposed resolution is sufficient, and recommends we leave the hash template unconstrained for now.

> Recommend that the Project Editor make the constrained declaration consistent with the definition in order to make the Working Paper internally consistent, and that the issue then be revisited.

> Move to Open.

Proposed resolution:

[To the editor: This resolution is merge-compatible to the resolution of 1078]

1. In 20.14 [function.objects]/2, header `<functional>` synopsis, change as indicated:

   >     // 20.6.17, hash function base template:
   >     template <ReferentType T> struct hash; // undefined

2. In 20.14.19 [unord.hash]/1 change as indicated:

   >     namespace std {
   >      template <class T>
   >      struct hash : public std::unary_function<T, std::size_t> {
   >      std::size_t operator()(T val) const;
   >      };
   >      template <ReferentType T> struct hash; // undefined
   >     }

3. In 20.14.19 [unord.hash]/2 change as indicated:

   > -2- For all library-provided specializations, the template instantiation `hash<T>` shall provide a public `operator()` with return type `std::size_t` to satisfy the concept requirement `Callable<const hash<T>, const T&>`. If `T` is an object type or reference to object, `hash<T>` shall be publicly derived from `std::unary_function<T, std::size_t>`. The return value of `operator()` is unspecified, except that equal arguments shall yield the same result. `operator()` shall not throw exceptions.

4. In 17.7 [support.rtti]/1, header `<typeinfo>` synopsis change as indicated:

   >     namespace std {
   >       class type_info;
   >       class type_index;
   >       template <classReferentType T> struct hash;