Topic: hash with qualifiers
Author: "'Geoffrey Romer' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 15 May 2014 17:03:09 -0700
Raw View
--001a11c126ba8e3a3804f9792377
Content-Type: text/plain; charset=UTF-8
Hi, all-
I'm considering writing a proposal to define std::hash for cv- and
ref-qualified types, which would forward to the corresponding unqualified
type (so specializing hash<Foo> would automatically give you hash<const
Foo>, hash<Foo&>, etc). This seems like such a no-brainer that the paper
would just be a paragraph or so of motivation, plus some wording, but I
assume if it were that simple it would already have been done. Does anyone
know of any obstacles or objections I should address?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c126ba8e3a3804f9792377
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi, all-<div><br></div><div>I'm considering writing a =
proposal to define std::hash for cv- and ref-qualified types, which would f=
orward to the corresponding unqualified type (so specializing hash<Foo&g=
t; would automatically give you hash<const Foo>, hash<Foo&>=
, etc). This seems like such a no-brainer that the paper would just be a pa=
ragraph or so of motivation, plus some wording, but I assume if it were tha=
t simple it would already have been done. Does anyone know of any obstacles=
or objections I should address?</div>
</div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c126ba8e3a3804f9792377--
.
Author: Diggory Blake <diggsey@googlemail.com>
Date: Thu, 15 May 2014 18:22:34 -0700 (PDT)
Raw View
------=_Part_49_19557805.1400203354889
Content-Type: text/plain; charset=UTF-8
Why is it necessary? Surely anything using std::hash should remove cv- and
ref- qualifiers before supplying a type as the template argument.
On Friday, 16 May 2014 01:03:09 UTC+1, Geoffrey Romer wrote:
>
> Hi, all-
>
> I'm considering writing a proposal to define std::hash for cv- and
> ref-qualified types, which would forward to the corresponding unqualified
> type (so specializing hash<Foo> would automatically give you hash<const
> Foo>, hash<Foo&>, etc). This seems like such a no-brainer that the paper
> would just be a paragraph or so of motivation, plus some wording, but I
> assume if it were that simple it would already have been done. Does anyone
> know of any obstacles or objections I should address?
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_49_19557805.1400203354889
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Why is it necessary? Surely anything using std::hash shoul=
d remove cv- and ref- qualifiers before supplying a type as the template ar=
gument.<br><br>On Friday, 16 May 2014 01:03:09 UTC+1, Geoffrey Romer wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hi, all-<div=
><br></div><div>I'm considering writing a proposal to define std::hash for =
cv- and ref-qualified types, which would forward to the corresponding unqua=
lified type (so specializing hash<Foo> would automatically give you h=
ash<const Foo>, hash<Foo&>, etc). This seems like such a no=
-brainer that the paper would just be a paragraph or so of motivation, plus=
some wording, but I assume if it were that simple it would already have be=
en done. Does anyone know of any obstacles or objections I should address?<=
/div>
</div>
</blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_49_19557805.1400203354889--
.
Author: "'Geoffrey Romer' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 15 May 2014 20:25:52 -0700
Raw View
--001a11c126ba876b2f04f97bf874
Content-Type: text/plain; charset=UTF-8
Thanks, I'll be sure to address that objection in the proposal.
My answer is basically, why make every consumer of std::hash jump through
hoops when we can fix it once and for all?
Anyway, that "surely" doesn't look so sure to me. For example, the
unordered containers are specified not to do that, and if even the
committee could make that (arguable) mistake, plenty of others will too.
For another, suppose you want to hash an ad-hoc collection of variables.
With this proposal, together with a separate extension for hashing tuples,
this could be as simple as
auto tup = std::tie(x, y, z); // or forward_as_tuple?
size_t
result = hash<decltype(tup)>()(tup);
Without automatic support for hashing qualified types, this code would be a
lot more complicated.
On May 15, 2014 6:22 PM, "Diggory Blake" <diggsey@googlemail.com> wrote:
> Why is it necessary? Surely anything using std::hash should remove cv- and
> ref- qualifiers before supplying a type as the template argument.
>
> On Friday, 16 May 2014 01:03:09 UTC+1, Geoffrey Romer wrote:
>>
>> Hi, all-
>>
>> I'm considering writing a proposal to define std::hash for cv- and
>> ref-qualified types, which would forward to the corresponding unqualified
>> type (so specializing hash<Foo> would automatically give you hash<const
>> Foo>, hash<Foo&>, etc). This seems like such a no-brainer that the paper
>> would just be a paragraph or so of motivation, plus some wording, but I
>> assume if it were that simple it would already have been done. Does anyone
>> know of any obstacles or objections I should address?
>>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c126ba876b2f04f97bf874
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">Thanks, I'll be sure to address that objection in the pr=
oposal.</p>
<p dir=3D"ltr">My answer is basically, why make every consumer of std::hash=
jump through hoops when we can fix it once and for all?</p>
<p dir=3D"ltr">Anyway, that "surely" doesn't look so sure to =
me. For example, the unordered containers are specified not to do that, and=
if even the committee could make that (arguable) mistake, plenty of others=
will too.</p>
<p dir=3D"ltr">For another, suppose you want to hash an ad-hoc collection o=
f variables. With this proposal, together with a separate extension for has=
hing tuples, this could be as simple as</p>
<div align=3D"left"><p dir=3D"ltr">auto tup =3D std::tie(x, y, z);=C2=A0 //=
or forward_as_tuple?<br>
</p>
</div><p dir=3D"ltr">size_t</p>
<div align=3D"left"><p dir=3D"ltr"> result =3D hash<decltype(tup)>()(=
tup);</p>
</div><p dir=3D"ltr"></p>
<p dir=3D"ltr">Without automatic support for hashing qualified types, this =
code would be a lot more complicated.</p>
<div class=3D"gmail_quote">On May 15, 2014 6:22 PM, "Diggory Blake&quo=
t; <<a href=3D"mailto:diggsey@googlemail.com">diggsey@googlemail.com</a>=
> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">Why is it necessary? Surely anything using std::hash shoul=
d remove cv- and ref- qualifiers before supplying a type as the template ar=
gument.<br><br>On Friday, 16 May 2014 01:03:09 UTC+1, Geoffrey Romer wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">Hi, all-<div><br></div><div>I'm considering writing a =
proposal to define std::hash for cv- and ref-qualified types, which would f=
orward to the corresponding unqualified type (so specializing hash<Foo&g=
t; would automatically give you hash<const Foo>, hash<Foo&>=
, etc). This seems like such a no-brainer that the paper would just be a pa=
ragraph or so of motivation, plus some wording, but I assume if it were tha=
t simple it would already have been done. Does anyone know of any obstacles=
or objections I should address?</div>
</div>
</blockquote></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c126ba876b2f04f97bf874--
.