From patchwork Wed Jan 2 16:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1020029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493285-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LfRulv+r"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43VGlR3WFDz9s4s for ; Thu, 3 Jan 2019 03:31:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=vI7PS4qYoLJX/rDUBI7N6v7GAoP9M8VK0Ruo6FMDIUVt5myTAbuNd JXfxqKBG7oomFIGQzo/9TtsGQJSyb7WlLCDrg35WwMkjtJ6WCKFVM4SbrEyyp++8 SdHEAe5XO3hIws8s/jdizj/w8BdvDjyDpTH47/uT1Ig/oRI++//hec= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=sJBkUqZpv6mMIIrG7xfcs4IRWmE=; b=LfRulv+roPTnRgtQHTAj lkzE+LMpLHAHVrC5RNcwDI0PqDerK3l+FKG9qtx9ZavCm8BkLTSFnYETJUocjcCa GkTzxRQF5QSiHNSTqVxOMzc2E/Nd5vyh7+YRrF0L9DN6JFtA9x1fQ67cB6ct9NAp aHZHd2I15J45LIgsx5feRF0= Received: (qmail 92573 invoked by alias); 2 Jan 2019 16:31:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 92548 invoked by uid 89); 2 Jan 2019 16:31:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2.0, usable X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Jan 2019 16:31:16 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82835C07EFFF; Wed, 2 Jan 2019 16:31:15 +0000 (UTC) Received: from localhost (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE7C55C22C; Wed, 2 Jan 2019 16:31:14 +0000 (UTC) Date: Wed, 2 Jan 2019 16:31:13 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Add more testcases for class template argument deduction of maps Message-ID: <20190102163113.GA1347@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.10.1 (2018-07-13) This adds additional tests for std::map and std::multimap CTAD. The tests ensure that deduction works for braced-init-list of value_type objects, and for pairs of input iterators (with both std::pair and value_type as the iterator's value_type). This ensures deduction from value_type still works, as well as the non-value_type cases in LWG 3025. Similar tests for unordered maps do not work, apparently because the constructor taking an initializer_list is not usable for deduction, and the deduction guide taking initializer_list> deduces key_type to be const. I am not addressing that. * testsuite/23_containers/map/cons/deduction.cc: Test deduction from initializer_list and from input iterator ranges. * testsuite/23_containers/multimap/cons/deduction.cc: Likewise. Tested x86_64-linux, committed to trunk. commit d595c72ef9482a8597493f49a263258dbe634776 Author: Jonathan Wakely Date: Wed Jan 2 15:42:29 2019 +0000 Add more testcases for class template argument deduction of maps This adds additional tests for std::map and std::multimap CTAD. The tests ensure that deduction works for braced-init-list of value_type objects, and for pairs of input iterators (with both std::pair and value_type as the iterator's value_type). This ensures deduction from value_type still works, as well as the non-value_type cases in LWG 3025. Similar tests for unordered maps do not work, apparently because the constructor taking an initializer_list is not usable for deduction, and the deduction guide taking initializer_list> deduces key_type to be const. I am not addressing that. * testsuite/23_containers/map/cons/deduction.cc: Test deduction from initializer_list and from input iterator ranges. * testsuite/23_containers/multimap/cons/deduction.cc: Likewise. diff --git a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc index 3880cd5e79d..f4195257e9c 100644 --- a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc @@ -3,32 +3,58 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::map::value_type; + +static_assert(std::is_same_v< + decltype(std::map{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::map>); static_assert(std::is_same_v< decltype(std::map{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), std::map>); +static_assert(std::is_same_v< + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::map>); + static_assert(std::is_same_v< decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), std::map>); static_assert(std::is_same_v< - decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - std::less{}, {}}), + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less{}, {}}), std::map>); static_assert(std::is_same_v< decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - {}}), + std::less{}, {}}), + std::map>); + +/* This is not deducible, {} could be deduced as _Compare or _Allocator. +static_assert(std::is_same_v< + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), + std::map>); +*/ + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::map>); static_assert(std::is_same_v< - decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - {}, SimpleAllocator>{}}), + decltype(std::map{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator{}}), std::map, - SimpleAllocator>>>); + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator{}}), + std::map, + SimpleAllocator>>); void f() { @@ -39,13 +65,13 @@ void f() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - std::less{}, - std::allocator>{}}), + std::less{}, + std::allocator{}}), std::map>); - + static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - std::less{}, {}}), + std::less{}, {}}), std::map>); static_assert(std::is_same_v< @@ -55,14 +81,95 @@ void f() static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - {}, - std::allocator>{}}), + {}, + std::allocator{}}), std::map>); static_assert(std::is_same_v< decltype(std::map{x.begin(), x.end(), - {}, - SimpleAllocator>{}}), + {}, + SimpleAllocator{}}), std::map, - SimpleAllocator>>>); + SimpleAllocator>>); +} + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; + +void g() +{ + value_type array[1]; + test_container x(array); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end())), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, {}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end(), + {})), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); +} + +void h() +{ + std::pair array[1]; + test_container, input_iterator_wrapper> x(array); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end())), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less{}, {}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end(), + {})), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + std::allocator{}}), + std::map>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::map, + SimpleAllocator>>); } diff --git a/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc index ee48bfda26b..2f9373a5bef 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc @@ -3,32 +3,60 @@ #include #include +#include using __gnu_test::SimpleAllocator; +using value_type = std::multimap::value_type; + +static_assert(std::is_same_v< + decltype(std::multimap{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), std::multimap>); +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::multimap>); + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), std::multimap>); +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less{}, {}}), + std::multimap>); + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, std::less{}, {}}), std::multimap>); +/* This is not deducible, {} could be deduced as _Compare or _Allocator. +static_assert(std::is_same_v< + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}}), + std::multimap>); +*/ + static_assert(std::is_same_v< decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}), std::multimap>); static_assert(std::is_same_v< - decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, - {}, SimpleAllocator>{}}), + decltype(std::multimap{{value_type{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator{}}), std::multimap, - SimpleAllocator>>>); + SimpleAllocator>>); + +static_assert(std::is_same_v< + decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator{}}), + std::multimap, + SimpleAllocator>>); void f() { @@ -39,30 +67,111 @@ void f() static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - std::less{}, - std::allocator>{}}), + std::less{}, + std::allocator{}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - std::less{}, {}}), + std::less{}, {}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap(x.begin(), x.end(), - {})), + {})), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), {}, - std::allocator>{}}), + std::allocator{}}), std::multimap>); static_assert(std::is_same_v< decltype(std::multimap{x.begin(), x.end(), - {}, - SimpleAllocator>{}}), + {}, + SimpleAllocator{}}), std::multimap, - SimpleAllocator>>>); + SimpleAllocator>>); +} + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; + +void g() +{ + value_type array[1]; + test_container x(array); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end())), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, {}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end(), + {})), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::multimap, + SimpleAllocator>>); +} + +void h() +{ + std::pair array[1]; + test_container, input_iterator_wrapper> x(array); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end())), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less{}, {}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end(), + {})), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + std::allocator{}}), + std::multimap>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + SimpleAllocator{}}), + std::multimap, + SimpleAllocator>>); }