From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 7BDC1389202B for ; Mon, 16 Nov 2020 07:26:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7BDC1389202B Received: by mail-ej1-x62c.google.com with SMTP id o9so22974419ejg.1 for ; Sun, 15 Nov 2020 23:26:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9sSSeybcQOoatzeEu6gxqDQAxoHvvhG9NkrZofwOCUA=; b=A1IZj7ani7VUz0kRnyuxFZuC+xNQfCWb37qIMefaLFjYW9D/cXSKilfm1yJxlWt8Ee dsIbrbrl+OAgKfmDEA/2RJKT627etzEAuDEql5ZYu5p5fUeEO7dTw75FsS7gLMfBVrCu 50yxm2LTfe5EZYzNVoSqe3mg3wABtR8ktJvbDMd7tPz2WjfsMeSOHcyt4dTVt03Cgbic lhAvSNuES7IT5JRzNouNOlVrjPVH4pbCORlWqnNjagXEa3xhOLhWTQqxXmx6baYHfVnC URsPthB8igm2PuWGp+GvXNPs8XbNcqh3lmB7RhZKV+we1abYo1nUAvQxtsM6QT0Z+yvc dF9Q== X-Gm-Message-State: AOAM530CP5ASrwrArt4vwmQmRcoqLVo0DhjDWIrxRDfdjYsmLwnPCKvE DGWVieEqPbLNqMpe/XCOfwWggkI8xZmRaGUO26E= X-Google-Smtp-Source: ABdhPJye7H589Ad3VQOu0XksfByoQnHnM9W7EAZkoPfnRUK9FrGKUPxQP220JU9Ou8DRb5gM5EjU1TpsB9x1t1g3vgo= X-Received: by 2002:a17:906:1253:: with SMTP id u19mr13091918eja.288.1605511603598; Sun, 15 Nov 2020 23:26:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= Date: Mon, 16 Nov 2020 08:26:32 +0100 Message-ID: Subject: Re: transparent proxy of string_view as key for associative containers. To: sotrdg sotrdg Cc: "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2020 07:26:45 -0000 Am Mo., 16. Nov. 2020 um 07:44 Uhr schrieb sotrdg sotrdg via Libstdc++ : > > The code fails to compile for both unordered_map and map. Is this a bug of libstdc++ or a defect of WG21? > #include > #include > #include > #include > > int main() > { > std::unordered_map umap; > std::string_view key{"a key"}; > auto p{umap.find(key)}; > std::map 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 #include #include #include struct hash_transparent { using is_transparent = void; template std::size_t operator()(const T& s) const { return std::hash()(s); } }; int main() { std::unordered_map> umap; std::string_view key{ "a key" }; auto p{umap.find(key)}; std::map> 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