public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* transparent proxy of string_view as key for associative containers.
@ 2020-11-16  6:43 sotrdg sotrdg
  2020-11-16  7:26 ` Daniel Krügler
  0 siblings, 1 reply; 6+ messages in thread
From: sotrdg sotrdg @ 2020-11-16  6:43 UTC (permalink / raw)
  To: libstdc++

The code fails to compile for both unordered_map and map. Is this a bug of libstdc++ or a defect of WG21?
#include<unordered_map>
#include<string>
#include<string_view>
#include<map>

int main()
{
                std::unordered_map<std::string,std::string> umap;
                std::string_view key{"a key"};
                auto p{umap.find(key)};
                std::map<std::string,std::string> map;
                auto p1{map.find(key)};
}
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: transparent proxy of string_view as key for associative containers.
  2020-11-16  6:43 transparent proxy of string_view as key for associative containers sotrdg sotrdg
@ 2020-11-16  7:26 ` Daniel Krügler
  2020-11-16  9:57   ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Krügler @ 2020-11-16  7:26 UTC (permalink / raw)
  To: sotrdg sotrdg; +Cc: libstdc++

Am Mo., 16. Nov. 2020 um 07:44 Uhr schrieb sotrdg sotrdg via Libstdc++
<libstdc++@gcc.gnu.org>:
>
> The code fails to compile for both unordered_map and map. Is this a bug of libstdc++ or a defect of WG21?
> #include<unordered_map>
> #include<string>
> #include<string_view>
> #include<map>
>
> int main()
> {
>                 std::unordered_map<std::string,std::string> umap;
>                 std::string_view key{"a key"};
>                 auto p{umap.find(key)};
>                 std::map<std::string,std::string> map;
>                 auto p1{map.find(key)};
> }

I don't see any WG21 defect involved here, but a mislead user expectation:

Let's start with the observation that this code isn't valid. To
activate transparent comparison, you need to provide function objects
that have the is_transparent tag defined, e.g. aomething like the
following should be more appropriate:

#include<unordered_map>
#include<string>
#include<string_view>
#include<map>

struct hash_transparent
{
    using is_transparent = void;

    template<class T>
    std::size_t operator()(const T& s) const
    {
        return std::hash<T>()(s);
    }
};

int main()
{
    std::unordered_map<std::string, std::string, hash_transparent,
std::equal_to<>> umap;
    std::string_view key{ "a key" };
    auto p{umap.find(key)};
    std::map<std::string, std::string, std::less<>> map;
    auto p1{map.find(key)};
}

Nonetheless, when you test this, you will still get a compile error
with gcc/clang for the unordered_map (Not for the map), so I'm
assuming that this feature has not been implemented yet. Visual Studio
2019 accepts that code, though.

- Daniel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: transparent proxy of string_view as key for associative containers.
  2020-11-16  7:26 ` Daniel Krügler
@ 2020-11-16  9:57   ` Jonathan Wakely
  2020-11-28 11:02     ` François Dumont
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2020-11-16  9:57 UTC (permalink / raw)
  To: Daniel Krügler; +Cc: sotrdg sotrdg, libstdc++

On 16/11/20 08:26 +0100, Daniel Krügler via Libstdc++ wrote:
>Am Mo., 16. Nov. 2020 um 07:44 Uhr schrieb sotrdg sotrdg via Libstdc++
><libstdc++@gcc.gnu.org>:
>>
>> The code fails to compile for both unordered_map and map. Is this a bug of libstdc++ or a defect of WG21?
>> #include<unordered_map>
>> #include<string>
>> #include<string_view>
>> #include<map>
>>
>> int main()
>> {
>>                 std::unordered_map<std::string,std::string> umap;
>>                 std::string_view key{"a key"};
>>                 auto p{umap.find(key)};
>>                 std::map<std::string,std::string> map;
>>                 auto p1{map.find(key)};
>> }
>
>I don't see any WG21 defect involved here, but a mislead user expectation:
>
>Let's start with the observation that this code isn't valid. To
>activate transparent comparison, you need to provide function objects
>that have the is_transparent tag defined, e.g. aomething like the
>following should be more appropriate:
>
>#include<unordered_map>
>#include<string>
>#include<string_view>
>#include<map>
>
>struct hash_transparent
>{
>    using is_transparent = void;
>
>    template<class T>
>    std::size_t operator()(const T& s) const
>    {
>        return std::hash<T>()(s);
>    }
>};
>
>int main()
>{
>    std::unordered_map<std::string, std::string, hash_transparent,
>std::equal_to<>> umap;
>    std::string_view key{ "a key" };
>    auto p{umap.find(key)};
>    std::map<std::string, std::string, std::less<>> map;
>    auto p1{map.find(key)};
>}
>
>Nonetheless, when you test this, you will still get a compile error
>with gcc/clang for the unordered_map (Not for the map), so I'm
>assuming that this feature has not been implemented yet.

Correct.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: transparent proxy of string_view as key for associative containers.
  2020-11-16  9:57   ` Jonathan Wakely
@ 2020-11-28 11:02     ` François Dumont
  2020-11-28 11:17       ` Ville Voutilainen
  0 siblings, 1 reply; 6+ messages in thread
From: François Dumont @ 2020-11-28 11:02 UTC (permalink / raw)
  To: libstdc++

Hi

     Just for information I am starting the work on this following this 
paper: http://wg21.link/p1690r1

François

On 16/11/20 10:57 am, Jonathan Wakely via Libstdc++ wrote:
> On 16/11/20 08:26 +0100, Daniel Krügler via Libstdc++ wrote:
>> Am Mo., 16. Nov. 2020 um 07:44 Uhr schrieb sotrdg sotrdg via Libstdc++
>> <libstdc++@gcc.gnu.org>:
>>>
>>> The code fails to compile for both unordered_map and map. Is this a 
>>> bug of libstdc++ or a defect of WG21?
>>> #include<unordered_map>
>>> #include<string>
>>> #include<string_view>
>>> #include<map>
>>>
>>> int main()
>>> {
>>> std::unordered_map<std::string,std::string> umap;
>>>                 std::string_view key{"a key"};
>>>                 auto p{umap.find(key)};
>>>                 std::map<std::string,std::string> map;
>>>                 auto p1{map.find(key)};
>>> }
>>
>> I don't see any WG21 defect involved here, but a mislead user 
>> expectation:
>>
>> Let's start with the observation that this code isn't valid. To
>> activate transparent comparison, you need to provide function objects
>> that have the is_transparent tag defined, e.g. aomething like the
>> following should be more appropriate:
>>
>> #include<unordered_map>
>> #include<string>
>> #include<string_view>
>> #include<map>
>>
>> struct hash_transparent
>> {
>>    using is_transparent = void;
>>
>>    template<class T>
>>    std::size_t operator()(const T& s) const
>>    {
>>        return std::hash<T>()(s);
>>    }
>> };
>>
>> int main()
>> {
>>    std::unordered_map<std::string, std::string, hash_transparent,
>> std::equal_to<>> umap;
>>    std::string_view key{ "a key" };
>>    auto p{umap.find(key)};
>>    std::map<std::string, std::string, std::less<>> map;
>>    auto p1{map.find(key)};
>> }
>>
>> Nonetheless, when you test this, you will still get a compile error
>> with gcc/clang for the unordered_map (Not for the map), so I'm
>> assuming that this feature has not been implemented yet.
>
> Correct.
>
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: transparent proxy of string_view as key for associative containers.
  2020-11-28 11:02     ` François Dumont
@ 2020-11-28 11:17       ` Ville Voutilainen
  2020-11-28 13:30         ` François Dumont
  0 siblings, 1 reply; 6+ messages in thread
From: Ville Voutilainen @ 2020-11-28 11:17 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++

On Sat, 28 Nov 2020 at 13:02, François Dumont via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Hi
>
>      Just for information I am starting the work on this following this
> paper: http://wg21.link/p1690r1

Thanks for the heads-up, because I was about to start doing that. All
yours, go ahead, I'll hack on something else.

I took a brief look at this, and we basically need to add the
templated overloads all the way down to the hash table,
but other than that, there doesn't seem to be anything too tedious in this.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: transparent proxy of string_view as key for associative containers.
  2020-11-28 11:17       ` Ville Voutilainen
@ 2020-11-28 13:30         ` François Dumont
  0 siblings, 0 replies; 6+ messages in thread
From: François Dumont @ 2020-11-28 13:30 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: libstdc++

On 28/11/20 12:17 pm, Ville Voutilainen wrote:
> On Sat, 28 Nov 2020 at 13:02, François Dumont via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
>> Hi
>>
>>       Just for information I am starting the work on this following this
>> paper: http://wg21.link/p1690r1
> Thanks for the heads-up, because I was about to start doing that. All
> yours, go ahead, I'll hack on something else.
>
> I took a brief look at this, and we basically need to add the
> templated overloads all the way down to the hash table,
> but other than that, there doesn't seem to be anything too tedious in this.

Yes, this is why I plan to give it a try :-)

And also because I think it is interesting to do so before continuing on 
PR96088:

https://gcc.gnu.org/pipermail/libstdc++/2020-October/051255.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-28 13:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16  6:43 transparent proxy of string_view as key for associative containers sotrdg sotrdg
2020-11-16  7:26 ` Daniel Krügler
2020-11-16  9:57   ` Jonathan Wakely
2020-11-28 11:02     ` François Dumont
2020-11-28 11:17       ` Ville Voutilainen
2020-11-28 13:30         ` François Dumont

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).