From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 044F6385783A for ; Sat, 19 Sep 2020 01:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 044F6385783A Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411--iRrvbFtP9WJkDqRFaKD7Q-1; Fri, 18 Sep 2020 21:08:13 -0400 X-MC-Unique: -iRrvbFtP9WJkDqRFaKD7Q-1 Received: by mail-qt1-f197.google.com with SMTP id c5so6731180qtd.12 for ; Fri, 18 Sep 2020 18:08:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uO617IXvYfSTeDykM9jw5LcK19pvbASnZdZ1a4E7si8=; b=KOBGr12ssq3dZWaq8qYx8TPzV3Ro3WmaR2qqN65wyypj1R3xnSROZ0nK1/0zKw1wDP 6tP4hXQU3F4we6RdmKxNkjIfrsZE4BNWo6CHR3SlDbOwybaXAFcZWXBWqFCF1nvEyGWn zU5kIyB1Wv8zI7HlzpCuQOAkojIngm/htsNZtoT+dIx/oKTK90ojTwRXXSUoLNMtoOtX xB/2IWlDpxrTZVBCoSPBClG0MDTWqkqDJY0nm1xqlbqK8S1Gm59aJe3zt9gS3wYvIeSb hLjFQbkXHfvSbJzakH9YtpwN6bfudfA2eeZyYWanu5BMcVikUtOoyQOfzS7CsUK8Vkjs /SFQ== X-Gm-Message-State: AOAM532xzyk1FjUUKrpvkeVyJnQkaJVXEqjKrNYVdpsj/pmiAvsiR/Ro WZwDxyHGhcGuY2XCCsjfa+bJ3Bh/IbqS7GKkhaR9Wwv4iQ5Blt3xhpK7wCbSYnkPH3u1z2McQCd HyG8vO4ofBJOr4pA= X-Received: by 2002:a05:620a:12f3:: with SMTP id f19mr28250034qkl.110.1600477692486; Fri, 18 Sep 2020 18:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyadJLY1nBDwvuKh0QDiFjdbrHSpOkqFGFdifnJxTyVlrIh+e7VoTkU9G5f3geIxgmhC8V8hg== X-Received: by 2002:a05:620a:12f3:: with SMTP id f19mr28250023qkl.110.1600477692276; Fri, 18 Sep 2020 18:08:12 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o188sm3314141qke.83.2020.09.18.18.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 18:08:11 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Mark some more algorithms constexpr for C++20 Date: Fri, 18 Sep 2020 21:08:03 -0400 Message-Id: <20200919010804.3509832-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.497.g54e85e7af1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-17.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Sat, 19 Sep 2020 01:08:16 -0000 As per P0202. Tested on x86_64-pc-linux-gnu. libstdc++-v3/ChangeLog: * include/bits/stl_algo.h (for_each_n): Mark constexpr for C++20. (search): Likewise for the overload that takes a searcher. * testsuite/25_algorithms/for_each/constexpr.cc: Test constexpr std::for_each_n. * testsuite/25_algorithms/search/constexpr.cc: Test constexpr std::search overload that takes a searcher. --- libstdc++-v3/include/bits/stl_algo.h | 2 ++ .../testsuite/25_algorithms/for_each/constexpr.cc | 12 ++++++++++++ .../testsuite/25_algorithms/search/constexpr.cc | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 550a15f2b3b..a0b96c61798 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -3832,6 +3832,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * If `__f` has a return value it is ignored. */ template + _GLIBCXX20_CONSTEXPR _InputIterator for_each_n(_InputIterator __first, _Size __n, _Function __f) { @@ -4251,6 +4252,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @return @p __searcher(__first,__last).first */ template + _GLIBCXX20_CONSTEXPR inline _ForwardIterator search(_ForwardIterator __first, _ForwardIterator __last, const _Searcher& __searcher) diff --git a/libstdc++-v3/testsuite/25_algorithms/for_each/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/for_each/constexpr.cc index 1bece35a0d9..b3aca23eccc 100644 --- a/libstdc++-v3/testsuite/25_algorithms/for_each/constexpr.cc +++ b/libstdc++-v3/testsuite/25_algorithms/for_each/constexpr.cc @@ -34,3 +34,15 @@ test() } static_assert(test()); + +constexpr bool +test_n() +{ + int tot = 0; + auto sum = [&total = tot](int i){ total += i; }; + auto sum2 = std::for_each_n(ca0.begin(), std::size(ca0)-1, sum); + + return tot == 55; +} + +static_assert(test_n()); diff --git a/libstdc++-v3/testsuite/25_algorithms/search/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/search/constexpr.cc index ba9437eced7..e34194cfc5d 100644 --- a/libstdc++-v3/testsuite/25_algorithms/search/constexpr.cc +++ b/libstdc++-v3/testsuite/25_algorithms/search/constexpr.cc @@ -31,6 +31,10 @@ test() cam.begin(), cam.end(), std::equal_to()); + const auto outtt2 + = std::search(ca0.begin(), ca0.end(), + std::default_searcher(cam.begin(), cam.end())); + return true; } -- 2.28.0.497.g54e85e7af1