public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: "François Dumont" <frs.dumont@gmail.com>
To: libstdc++@gcc.gnu.org
Subject: Re: transparent proxy of string_view as key for associative containers.
Date: Sat, 28 Nov 2020 12:02:08 +0100	[thread overview]
Message-ID: <a0796aba-d027-49a5-521d-3bd1ddf8673f@gmail.com> (raw)
In-Reply-To: <20201116095723.GP503596@redhat.com>

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.
>
>
>


  reply	other threads:[~2020-11-28 11:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  6:43 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 [this message]
2020-11-28 11:17       ` Ville Voutilainen
2020-11-28 13:30         ` François Dumont

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0796aba-d027-49a5-521d-3bd1ddf8673f@gmail.com \
    --to=frs.dumont@gmail.com \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).