Topic: string_view and associative container
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Tue, 7 Oct 2014 23:31:22 +0200
Raw View
Hello.
I tried to use a string_view to look up elements in a map<string,X> and got
surprised because it failed.
Looking further into it revealed that map::find takes an argument of type
const key_type& and string_view isn't convertible to string (and that is
a good thing)
I then asked myself why map::find takes a key_type argument when it really
just needs to have something that is LessThanComparable with key_type and
uses the same partial ordering.
Would a change of
iterator map::find(const key_type&)
to
template <typename K>
iterator map::find(const K&);
be reasonable?
In the default case this would still allow only key_type's since
map::compare defaults to less<key_type> and that prevents all other types,
and so the new version is compatible with the old one.
On the other hand this would allow one to declare a map using less<void>
as comparator and then every type that is comparable to key_type would
be useable for lookup of elements, and I think this would make the
associative containers a lot more powerful.
Of course the change should be applied to all lookup functions in all
associative containers if it is done.
/MF
--
---
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/.
.
Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 7 Oct 2014 17:45:56 -0400
Raw View
--bcaec51a7d2cd3a0420504dc1ff2
Content-Type: text/plain; charset=UTF-8
On Tue, Oct 7, 2014 at 5:31 PM, Magnus Fromreide <magfr@lysator.liu.se>
wrote:
> Hello.
>
> I tried to use a string_view to look up elements in a map<string,X> and got
> surprised because it failed.
>
> Looking further into it revealed that map::find takes an argument of type
> const key_type& and string_view isn't convertible to string (and that is
> a good thing)
>
> I then asked myself why map::find takes a key_type argument when it really
> just needs to have something that is LessThanComparable with key_type and
> uses the same partial ordering.
>
> Would a change of
>
> iterator map::find(const key_type&)
>
> to
>
> template <typename K>
> iterator map::find(const K&);
>
> be reasonable?
>
>
Already in C++14: http://en.cppreference.com/w/cpp/container/map/find
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd
--
---
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/.
--bcaec51a7d2cd3a0420504dc1ff2
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tue, Oct 7, 2014 at 5:31 PM, Magnus Fromreide <span dir=
=3D"ltr"><<a href=3D"mailto:magfr@lysator.liu.se" target=3D"_blank">magf=
r@lysator.liu.se</a>></span> wrote:<br><div class=3D"gmail_extra"><div c=
lass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello.<br>
<br>
I tried to use a string_view to look up elements in a map<string,X> a=
nd got<br>
surprised because it failed.<br>
<br>
Looking further into it revealed that map::find takes an argument of type<b=
r>
const key_type& and string_view isn't convertible to string (and th=
at is<br>
a good thing)<br>
<br>
I then asked myself why map::find takes a key_type argument when it really<=
br>
just needs to have something that is LessThanComparable with key_type and<b=
r>
uses the same partial ordering.<br>
<br>
Would a change of<br>
<br>
iterator map::find(const key_type&)<br>
<br>
to<br>
<br>
template <typename K><br>
iterator map::find(const K&);<br>
<br>
be reasonable?<br>
<br></blockquote></div><br></div><div class=3D"gmail_extra">Already in C++1=
4: <a href=3D"http://en.cppreference.com/w/cpp/container/map/find">http://e=
n.cppreference.com/w/cpp/container/map/find</a><br clear=3D"all"></div><div=
class=3D"gmail_extra"><br>-- <br>Zhihao Yuan, ID lichray<br>The best way t=
o predict the future is to invent it.<br>__________________________________=
_________________<br>4BSD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_=
blank">http://bit.ly/blog4bsd</a>
</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 />
--bcaec51a7d2cd3a0420504dc1ff2--
.