Title
Is std::hash a constrained template or not?
Status
nad concepts
Section
[unord.hash]
Submitter
Alisdair Meredith

Created on 2009-03-19.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

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

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

    // 20.6.17, hash function base template:
    template <ReferentType T> struct hash; // undefined
    
  2. In [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 [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 [support.rtti]/1, header <typeinfo> synopsis change as indicated:

    namespace std {
      class type_info;
      class type_index;
      template <classReferentType T> struct hash;
    
Date: 2010-10-21.18:28:33

[ 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.

Date: 2009-03-22.00:00:00

[ 2009-03-22 Daniel provided wording. ]

Date: 2011-03-05.21:44:45

Is std::hash a constrained template or not?

According to class template hash [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 [function.objects] the template is declared as:

template <ReferentType T> struct hash;

which would make hash a constrained template.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg591
2010-10-21 18:28:33adminsetmessages: + msg590
2010-10-21 18:28:33adminsetmessages: + msg589
2009-03-19 00:00:00admincreate