On 2017-04-16 20:54, Ville Voutilainen wrote:
On 16 April 2017 at 20:51, Giuseppe D'Angelo
<[email protected]> wrote:
Il 16/04/2017 18:32, Corentin ha scritto:
More on point:
* You don't actually need to include anything from the STL to
implement std::hash.
You actually do: you need <functional> to see the primary template for
std::hash (otherwise you can't specialize it). Also, how to implement
it
is another burden (see the other discussion).
You don't need to include a header to do that:
namespace std {
template <class T> struct hash;
}
Now you can specialize hash for your own types.
I don't think that violates any rule; it's not adding a declaration to
namespace std, as that
declaration is already there.
Does the standard guarantee that this is the declaration for std::hash?
For vector etc, implementations are allowed to add extra, defaulted
template arguments. If an implementation makes use of that, e.g. to have
a void slot there for SFINAE, then the above declaration is wrong.
Also, it's not enough to have a std::hash primary template; you also
need the std::hash specialisations for built-in (and enum) types,
otherwise yoou may end up with "specialised after instantiation" errors,
though that could be worked around by making std::hash<X>::op() a
template. I use that trick already for std::hash<QSizePolicy>, to pick
up any constexpr the underlying std::hash specialisation may provide.
Thanks,
Marc
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development