Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++14 status.

2109. Incorrect requirements forhash specializations

Section: 19.5.7[syserr.hash], 20.3.3[util.smartptr.hash], 22.10.19[unord.hash], 17.7.6[type.index.synopsis], 27.4.6[basic.string.hash], 23.3.14[vector.bool], 32.4.3.2[thread.thread.id]Status:C++14Submitter: Daniel KrüglerOpened: 2011-12-04Last modified: 2016-01-28

Priority:Not Prioritized

View all issues withC++14 status.

Discussion:

20.3.3[util.smartptr.hash] p2 is specified as follows:

Requires: the template specializations shall meet the requirements of class templatehash (20.8.12).

The problem here is the usage of aRequires element, which is actually a pre-conditionthat auser of a component has to satisfy. But the intent of this wording is actuallyto be a requirement on implementations. TheRequires element should be removed here andthe wording should be improved to say what it was intended for.

We have similar situations in basically all other places where the specification of library-providedhash specializations is defined. Usually, theRequires element is incorrect. In thespecial case ofhash<unique_ptr<T, D>> the implementation depends on the behaviour ofhash specializations, that could be user-provided. In this casethe specification needs to separate the requirements on these specializations and thosethat are imposed on the implementation.

[2012, Kona]

Update wording and move to Review.

Believe a simpler formulation is to simply string the termRequires: and leave thecurrent wording intact, rather than strike the whole clause and replace it.

[Originally proposed wording for reference

  1. Change 19.5.7[syserr.hash] as indicated:

    template <> struct hash<error_code>;

    -1-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<system_error> provides a definition for a specialization of the templatehash<error_code>. The requirements for the members of this specialization are given in sub-clause 22.10.19[unord.hash].

  2. Change 22.9.3[bitset.hash] as indicated:

    template <size_t N> struct hash<bitset<N> >;

    -1-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<bitset> provides a definition for a partial specialization of thehash class template for specializations of class templatebitset<N>. The requirements for the members of instantiations of this specialization are given in sub-clause 22.10.19[unord.hash].

  3. Change 20.3.3[util.smartptr.hash] as indicated:

    template <class T, class D> struct hash<unique_ptr<T, D> >;

    -1-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<memory> provides a definition for a partial specialization of thehash class template for specializations of class templateunique_ptr<T, D>. The requirements for the members of instantiations of this specialization are given in sub-clause 22.10.19[unord.hash]. For an objectp of typeUP, whereUP isunique_ptr<T, D>,hash<UP>()(p) shall evaluate to the same value ashash<typename UP::pointer>()(p.get()).The specializationhash<typename UP::pointer> shall be well-formed.

    -?-Requires: The specializationhash<typename UP::pointer> shall be well-formed and well-defined [Note: the general requirements of class templatehash (22.10.19[unord.hash]) are implied —end note].

    template <class T> struct hash<shared_ptr<T> >;

    -2-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<memory> provides a definition for a partial specialization of thehash class template for specializations of class templateshared_ptr<T>. The requirements for the members of instantiations of this specialization are given in sub-clause 22.10.19[unord.hash]. For an objectp of typeshared_ptr<T>,hash<shared_ptr<T> >()(p) shall evaluate to the same value ashash<T*>()(p.get()).

  4. Change 22.10.19[unord.hash] p2 as indicated: [Comment: For unknownreasons the extended integer types are not mentioned here, which looks like an oversight tome and makes also the wording more complicated. See2119(i) for this partof the problem. —end comment]

    template <> struct hash<bool>;template <> struct hash<char>;[…]template <> struct hash<long double>;template <class T> struct hash<T*>;

    -2-Requires: the template specializations shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<functional> provides definitions for specializations of thehash class template for eachcv-unqualified arithmetic type except for the extended integer types. This header also provides a definition for a partial specialization of thehash class template for any pointer type. The requirements for the members of these specializations are given in sub-clause 22.10.19[unord.hash].

  5. Change [type.index.hash] p1 as indicated:

    template <> struct hash<type_index>;

    -1-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<typeindex> provides a definition for a specialization of the templatehash<type_index>. The requirements for the members of this specialization are given in sub-clause 22.10.19[unord.hash]. For an objectindex of typetype_index,hash<type_index>()(index) shall evaluate to the same result asindex.hash_code().

  6. Change 27.4.6[basic.string.hash] p1 as indicated:

    template <> struct hash<string>;template <> struct hash<u16string>;template <> struct hash<u32string>;template <> struct hash<wstring>;

    -1-Requires: the template specializations shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<string> provides definitions for specializations of thehash class template for the typesstring,u16string,u32string, andwstring. The requirements for the members of these specializations are given in sub-clause 22.10.19[unord.hash].

  7. Change 23.3.14[vector.bool] p7 as indicated:

    template <class Allocator> struct hash<vector<bool, Allocator> >;

    -7-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<vector> provides a definition for a partial specialization of thehash class template for specializations of class templatevector<bool, Allocator>. The requirements for the members of instantiations of this specialization are given in sub-clause 22.10.19[unord.hash].

  8. Change 32.4.3.2[thread.thread.id] p14 as indicated:

    template <> struct hash<thread::id>;

    -14-Requires: the template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash])The header<thread> provides a definition for a specialization of the templatehash<thread::id>. The requirements for the members of this specialization are given in sub-clause 22.10.19[unord.hash].

]

[2012, Portland: Move to Tentatively Ready]

No further wording issues, so move to Tentatively Ready (post meeting issues processing).

[2013-04-20 Bristol]

Proposed resolution:

  1. Change 19.5.7[syserr.hash] as indicated:

    template <> struct hash<error_code>;

    -1-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash].

  2. Change 22.9.3[bitset.hash] as indicated:

    template <size_t N> struct hash<bitset<N> >;

    -1-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]).

  3. Change 20.3.3[util.smartptr.hash] as indicated:

    template <class T, class D> struct hash<unique_ptr<T, D> >;

    -1-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]). For an objectp of typeUP, whereUP isunique_ptr<T, D>,hash<UP>()(p) shall evaluate to the same value ashash<typename UP::pointer>()(p.get()).The specializationhash<typename UP::pointer> shall be well-formed.

    -?-Requires: The specializationhash<typename UP::pointer> shall be well-formed and well-defined, and shall meet the requirements of class templatehash (22.10.19[unord.hash]).

    template <class T> struct hash<shared_ptr<T> >;

    -2-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]). For an objectp of typeshared_ptr<T>,hash<shared_ptr<T> >()(p) shall evaluate to the same value ashash<T*>()(p.get()).

  4. Change 22.10.19[unord.hash] p2 as indicated: [Comment: For unknownreasons the extended integer types are not mentioned here, which looks like an oversight tome and makes also the wording more complicated. See2119(i) for this partof the problem. —end comment]

    template <> struct hash<bool>;template <> struct hash<char>;[…]template <> struct hash<long double>;template <class T> struct hash<T*>;

    -2-Requires: tThe template specializations shall meet the requirements of class templatehash (22.10.19[unord.hash]).

  5. Change [type.index.hash] p1 as indicated:

    template <> struct hash<type_index>;

    -1-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]). For an objectindex of typetype_index,hash<type_index>()(index) shall evaluate to the same result asindex.hash_code().

  6. Change 27.4.6[basic.string.hash] p1 as indicated:

    template <> struct hash<string>;template <> struct hash<u16string>;template <> struct hash<u32string>;template <> struct hash<wstring>;

    -1-Requires: tThe template specializations shall meet the requirements of class templatehash (22.10.19[unord.hash]).

  7. Change 23.3.14[vector.bool] p7 as indicated:

    template <class Allocator> struct hash<vector<bool, Allocator> >;

    -7-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]).

  8. Change 32.4.3.2[thread.thread.id] p14 as indicated:

    template <> struct hash<thread::id>;

    -14-Requires: tThe template specialization shall meet the requirements of class templatehash (22.10.19[unord.hash]).


[8]ページ先頭

©2009-2026 Movatter.jp