From patchwork Thu Aug 1 17:16:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1140650 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-506014-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="W+uNX3zk"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=verizon.net header.i=@verizon.net header.b="BusCWFVm"; 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 45zxls1c3gz9sDQ for ; Fri, 2 Aug 2019 03:16:24 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:references:from:reply-to:message-id:date :mime-version:in-reply-to:content-type; q=dns; s=default; b=kqQ4 ptds2SVDeMdSdlrd474Xe3P+tsIF4ASC8C07qafx1pqR5P47wIloPM3vlsK5i8IO GgzONhzhjv6BJ0wqbRK3VXAh0yEi444UXorSX3erEu9CwWjMNTWiSs7qoea27sup 5aOPzYxzHLwf9HE5P98tzEQu4n3SSTOwo5Xgiiw= 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 :subject:to:cc:references:from:reply-to:message-id:date :mime-version:in-reply-to:content-type; s=default; bh=dhdJgtk0Gu KCRLOVyyxjHMOVT4k=; b=W+uNX3zkPdb28217iVN4UZBGvT8CNzyqNGmC5ONiIY cLPchkzjd5MStRR6i9VEMBsnpNMGkRACTv6uAYjIerKSdRAXrHQRKvSq5f2FGE6M idLzG8lORFHeHwviYgpXQY7BmTvxbHdJw7nE7bM1YwZnILnsLuAePsp6Z2BVYwtl o= Received: (qmail 96710 invoked by alias); 1 Aug 2019 17:16:15 -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 96696 invoked by uid 89); 1 Aug 2019 17:16:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:sonic30, H*RU:sk:sonic30, HX-Spam-Relays-External:sk:sonic30, HX-HELO:sk:sonic30 X-HELO: sonic309-14.consmr.mail.bf2.yahoo.com Received: from sonic309-14.consmr.mail.bf2.yahoo.com (HELO sonic309-14.consmr.mail.bf2.yahoo.com) (74.6.129.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 17:16:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048; t=1564679765; bh=82xh7BqQjh+EfHJs5e1XqQEOcObMb1iTRA7EF1tXBuA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=BusCWFVmYNtaEwixgBMouPhzgXnhHbRy2rjpTbZ2O+2EMnVZlNhIBpDrWdgbATxCSTzDnsTjPbtfbjzC9rB1CMjanzQO0GALGXhScviqDg/mUQZWdelna8bavNnlI5sy/9/J7HVnLxWMIVczgv2gCieQL496ErPMcYNb545mcLi3cYeWhG7CFCOqz7XiD1709HE9OHwIisZTzyf7aNfHVQayx7RWx4chPYaOqO48kYsEen/VhVK/jKiDYIygbl6nR3H1bY9QfhS2NFFnTcQBCDiPVzGLuPyqGrnF8N5xV0ygE/B2xyuX8PYd5zK+3IV3F6bJe3KLBqty0udCmDQWMg== Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.bf2.yahoo.com with HTTP; Thu, 1 Aug 2019 17:16:05 +0000 Received: by smtp402.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID dbd5cde7307fc11b7d109230093dc8e4; Thu, 01 Aug 2019 17:16:04 +0000 (UTC) Subject: [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions. To: Jonathan Wakely , "libstdc++@gcc.gnu.org" Cc: Ville Voutilainen , gcc-patches References: <20190702121102.GL4665@redhat.com> <7c8fcbb4-b39a-86bc-5d7e-9a15056a035a@verizon.net> <20190801105650.GO9487@redhat.com> <7b28c65f-744b-5201-90ca-3e0a02782c3a@verizon.net> X-Patchwork-Original-From: "Ed Smith-Rowland via gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: Ed Smith-Rowland <3dw4rd@verizon.net> Message-ID: <44a98bfa-bfba-9626-94eb-b3a7393f2ab2@verizon.net> Date: Thu, 1 Aug 2019 13:16:03 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <7b28c65f-744b-5201-90ca-3e0a02782c3a@verizon.net> Greetings, Here is a patch for C++20 p0879 - Constexpr for swap and swap related functions. This essentially constexprifies the rest of . Built and tested with C++20 (and pre-c++20) on x86_64-linux. Ok? Regards, Ed Smith-Rowland 2019-08-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement C++20 p0879 - Constexpr for swap and swap related functions. * include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms): New macro. (iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap, prev_permutation, push_heap, reverse, rotate, sort_heap, swap, swap_ranges, nth_element, partial_sort, sort): Add constexpr. * include/bits/move.h (swap): Add constexpr. * include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse, __gcd, __rotate, rotate, __partition, __heap_select, __partial_sort_copy, partial_sort_copy, __unguarded_partition, __unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort, __introselect, __chunk_insertion_sort, next_permutation, prev_permutation, partition, partial_sort, nth_element, sort, __iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr. * include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr. * include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap, __pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap): Add constexpr. * include/std/type_traits (swap): Add constexpr. * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr. * testsuite/25_algorithms/iter_swap/constexpr.cc: New test. * testsuite/25_algorithms/make_heap/constexpr.cc: New test. * testsuite/25_algorithms/next_permutation/constexpr.cc: New test. * testsuite/25_algorithms/nth_element/constexpr.cc: New test. * testsuite/25_algorithms/partial_sort/constexpr.cc: New test. * testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test. * testsuite/25_algorithms/partition/constexpr.cc: New test. * testsuite/25_algorithms/pop_heap/constexpr.cc: New test. * testsuite/25_algorithms/prev_permutation/constexpr.cc: New test. * testsuite/25_algorithms/push_heap/constexpr.cc: New test. * testsuite/25_algorithms/reverse/constexpr.cc: New test. * testsuite/25_algorithms/rotate/constexpr.cc: New test. * testsuite/25_algorithms/sort/constexpr.cc: New test. * testsuite/25_algorithms/sort_heap/constexpr.cc: New test. * testsuite/25_algorithms/swap/constexpr.cc: New test. * testsuite/25_algorithms/swap_ranges/constexpr.cc: New test. diff --git a/libstdc++-v3/include/bits/algorithmfwd.h b/libstdc++-v3/include/bits/algorithmfwd.h index 99491db1c5e..24b6849e53e 100644 --- a/libstdc++-v3/include/bits/algorithmfwd.h +++ b/libstdc++-v3/include/bits/algorithmfwd.h @@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L # define __cpp_lib_constexpr_algorithms 201711L +# define __cpp_lib_constexpr_swap_algorithms 201712L #endif #if __cplusplus >= 201103L @@ -377,6 +378,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + _GLIBCXX20_CONSTEXPR void iter_swap(_FIter1, _FIter2); @@ -391,10 +393,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION lower_bound(_FIter, _FIter, const _Tp&, _Compare); template + _GLIBCXX20_CONSTEXPR void make_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void make_heap(_RAIter, _RAIter, _Compare); @@ -478,10 +482,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // mismatch template + _GLIBCXX20_CONSTEXPR bool next_permutation(_BIter, _BIter); template + _GLIBCXX20_CONSTEXPR bool next_permutation(_BIter, _BIter, _Compare); @@ -496,10 +502,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // partial_sort template + _GLIBCXX20_CONSTEXPR _RAIter partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR _RAIter partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare); @@ -519,26 +527,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + _GLIBCXX20_CONSTEXPR void pop_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void pop_heap(_RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR bool prev_permutation(_BIter, _BIter); template + _GLIBCXX20_CONSTEXPR bool prev_permutation(_BIter, _BIter, _Compare); template + _GLIBCXX20_CONSTEXPR void push_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void push_heap(_RAIter, _RAIter, _Compare); @@ -579,6 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // replace_if template + _GLIBCXX20_CONSTEXPR void reverse(_BIter, _BIter); @@ -590,6 +605,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline namespace _V2 { template + _GLIBCXX20_CONSTEXPR _FIter rotate(_FIter, _FIter, _FIter); } @@ -613,10 +629,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif template + _GLIBCXX20_CONSTEXPR void sort_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void sort_heap(_RAIter, _RAIter, _Compare); @@ -628,15 +646,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // For C++11 swap() is declared in . template + _GLIBCXX20_CONSTEXPR inline void swap(_Tp& __a, _Tp& __b); template + _GLIBCXX20_CONSTEXPR inline void swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]); #endif template + _GLIBCXX20_CONSTEXPR _FIter2 swap_ranges(_FIter1, _FIter1, _FIter2); @@ -783,22 +804,27 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO mismatch(_IIter1, _IIter1, _IIter2, _BinaryPredicate); template + _GLIBCXX20_CONSTEXPR void nth_element(_RAIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void nth_element(_RAIter, _RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void partial_sort(_RAIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void partial_sort(_RAIter, _RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR _BIter partition(_BIter, _BIter, _Predicate); @@ -892,10 +918,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare); template + _GLIBCXX20_CONSTEXPR void sort(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void sort(_RAIter, _RAIter, _Compare); diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index e3ddeb563b4..d7c7068e29c 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -175,6 +175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return Nothing. */ template + _GLIBCXX20_CONSTEXPR inline #if __cplusplus >= 201103L typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>, @@ -199,6 +200,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 809. std::swap should be overloaded for array types. /// Swap the contents of two arrays. template + _GLIBCXX20_CONSTEXPR inline #if __cplusplus >= 201103L typename enable_if<__is_swappable<_Tp>::value>::type diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index 0d707250d2e..bece93379de 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -74,6 +74,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Swaps the median value of *__a, *__b and *__c under __comp to *__result template + _GLIBCXX20_CONSTEXPR void __move_median_to_first(_Iterator __result,_Iterator __a, _Iterator __b, _Iterator __c, _Compare __comp) @@ -1162,6 +1163,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * overloaded for bidirectional iterators. */ template + _GLIBCXX20_CONSTEXPR void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) @@ -1182,6 +1184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * overloaded for random access iterators. */ template + _GLIBCXX20_CONSTEXPR void __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) @@ -1210,6 +1213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * swaps @p *(__first+i) and @p *(__last-(i+1)) */ template + _GLIBCXX20_CONSTEXPR inline void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) { @@ -1263,6 +1267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * It returns the greatest common divisor of two integer values. */ template + _GLIBCXX20_CONSTEXPR _EuclideanRingElement __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n) { @@ -1280,6 +1285,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function for the rotate algorithm. template + _GLIBCXX20_CONSTEXPR _ForwardIterator __rotate(_ForwardIterator __first, _ForwardIterator __middle, @@ -1321,6 +1327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function for the rotate algorithm. template + _GLIBCXX20_CONSTEXPR _BidirectionalIterator __rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, @@ -1359,6 +1366,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function for the rotate algorithm. template + _GLIBCXX20_CONSTEXPR _RandomAccessIterator __rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, @@ -1465,6 +1473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * for each @p n in the range @p [0,__last-__first). */ template + _GLIBCXX20_CONSTEXPR inline _ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) @@ -1520,6 +1529,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function... template + _GLIBCXX20_CONSTEXPR _ForwardIterator __partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) @@ -1545,6 +1555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function... template + _GLIBCXX20_CONSTEXPR _BidirectionalIterator __partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) @@ -1699,6 +1710,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function for the sort routines. template + _GLIBCXX20_CONSTEXPR void __heap_select(_RandomAccessIterator __first, _RandomAccessIterator __middle, @@ -1714,6 +1726,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template + _GLIBCXX20_CONSTEXPR _RandomAccessIterator __partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, @@ -1768,6 +1781,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The value returned is @p __result_first+N. */ template + _GLIBCXX20_CONSTEXPR inline _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, @@ -1818,6 +1832,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template + _GLIBCXX20_CONSTEXPR inline _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, @@ -1931,6 +1946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function... template + _GLIBCXX20_CONSTEXPR _RandomAccessIterator __unguarded_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, @@ -1952,6 +1968,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function... template + _GLIBCXX20_CONSTEXPR inline _RandomAccessIterator __unguarded_partition_pivot(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -1963,6 +1980,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_CONSTEXPR inline void __partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, @@ -1975,6 +1993,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// This is a helper function for the sort routine. template + _GLIBCXX20_CONSTEXPR void __introsort_loop(_RandomAccessIterator __first, _RandomAccessIterator __last, @@ -1998,6 +2017,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // sort template + _GLIBCXX20_CONSTEXPR inline void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -2012,6 +2032,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_CONSTEXPR void __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Size __depth_limit, @@ -2728,6 +2749,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template + _GLIBCXX20_CONSTEXPR void __chunk_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, @@ -2997,6 +3019,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * is the largest of the set, the smallest is generated and false returned. */ template + _GLIBCXX20_CONSTEXPR inline bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) @@ -3029,6 +3052,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * smallest is generated and false returned. */ template + _GLIBCXX20_CONSTEXPR inline bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) @@ -3098,6 +3122,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * returned. */ template + _GLIBCXX20_CONSTEXPR inline bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) @@ -3130,6 +3155,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * the largest is generated and false returned. */ template + _GLIBCXX20_CONSTEXPR inline bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) @@ -4757,6 +4783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @p stable_partition() if this is needed. */ template + _GLIBCXX20_CONSTEXPR inline _ForwardIterator partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) @@ -4790,6 +4817,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * the range @p [__middle,__last) then *j<*i and *k<*i are both false. */ template + _GLIBCXX20_CONSTEXPR inline void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, @@ -4828,6 +4856,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * are both false. */ template + _GLIBCXX20_CONSTEXPR inline void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, @@ -4864,6 +4893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * holds that *j < *i is false. */ template + _GLIBCXX20_CONSTEXPR inline void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) @@ -4903,6 +4933,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * holds that @p __comp(*j,*i) is false. */ template + _GLIBCXX20_CONSTEXPR inline void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) @@ -4940,6 +4971,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @p stable_sort() if this is needed. */ template + _GLIBCXX20_CONSTEXPR inline void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -4970,6 +5002,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO * @p stable_sort() if this is needed. */ template + _GLIBCXX20_CONSTEXPR inline void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index ab1ff5185d4..36bb9ccb777 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -136,6 +136,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __iter_swap { template + _GLIBCXX20_CONSTEXPR static void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) { @@ -151,6 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __iter_swap { template + _GLIBCXX20_CONSTEXPR static void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) { @@ -170,6 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * iterators themselves. */ template + _GLIBCXX20_CONSTEXPR inline void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) { @@ -216,6 +219,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The ranges must not overlap. */ template + _GLIBCXX20_CONSTEXPR _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) diff --git a/libstdc++-v3/include/bits/stl_heap.h b/libstdc++-v3/include/bits/stl_heap.h index d9530e66621..7eb12f04321 100644 --- a/libstdc++-v3/include/bits/stl_heap.h +++ b/libstdc++-v3/include/bits/stl_heap.h @@ -129,6 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template + _GLIBCXX20_CONSTEXPR void __push_heap(_RandomAccessIterator __first, _Distance __holeIndex, _Distance __topIndex, _Tp __value, @@ -155,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * [__first,__last) is a valid heap. */ template + _GLIBCXX20_CONSTEXPR inline void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -190,6 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * performed using comp. */ template + _GLIBCXX20_CONSTEXPR inline void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -215,6 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template + _GLIBCXX20_CONSTEXPR void __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex, _Distance __len, _Tp __value, _Compare __comp) @@ -244,6 +248,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_CONSTEXPR inline void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __result, _Compare& __comp) @@ -272,6 +277,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * heap. */ template + _GLIBCXX20_CONSTEXPR inline void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -305,6 +311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * heap. Comparisons are made using comp. */ template + _GLIBCXX20_CONSTEXPR inline void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -327,6 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_CONSTEXPR void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) @@ -361,6 +369,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * This operation makes the elements in [__first,__last) into a heap. */ template + _GLIBCXX20_CONSTEXPR inline void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -387,6 +396,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Comparisons are made using __comp. */ template + _GLIBCXX20_CONSTEXPR inline void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) @@ -403,6 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_CONSTEXPR void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) @@ -423,6 +434,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * This operation sorts the valid heap in the range [__first,__last). */ template + _GLIBCXX20_CONSTEXPR inline void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -450,6 +462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * Comparisons are made using __comp. */ template + _GLIBCXX20_CONSTEXPR inline void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9428dadc9d7..b31c26ab381 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2695,6 +2695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; template + _GLIBCXX20_CONSTEXPR inline typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>, is_move_constructible<_Tp>, @@ -2704,6 +2705,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION is_nothrow_move_assignable<_Tp>>::value); template + _GLIBCXX20_CONSTEXPR inline typename enable_if<__is_swappable<_Tp>::value>::type swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) diff --git a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc index d3b3540deb4..07dd7fbfac1 100644 --- a/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc +++ b/libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc @@ -165,10 +165,12 @@ namespace std // 25.2.2, swap: #if __cplusplus < 201103L template + _GLIBCXX20_CONSTEXPR void swap(_Tp&, _Tp& b); template + _GLIBCXX20_CONSTEXPR void swap(_Tp (&)[_Nm], _Tp (&)[_Nm]); #else @@ -178,10 +180,12 @@ namespace std #endif template + _GLIBCXX20_CONSTEXPR _FIter2 swap_ranges(_FIter1 first1, _FIter1, _FIter2); template + _GLIBCXX20_CONSTEXPR void iter_swap(_FIter1, _FIter2 b); @@ -295,6 +299,7 @@ namespace std unique_copy(_IIter, _IIter, _OIter, _BinaryPredicate); template + _GLIBCXX20_CONSTEXPR void reverse(_BIter, _BIter); @@ -304,6 +309,7 @@ namespace std reverse_copy(_BIter, _BIter, _OIter); template + _GLIBCXX20_CONSTEXPR void rotate(_FIter, _FIter, _FIter); @@ -322,6 +328,7 @@ namespace std // 25.2.12, partitions: template + _GLIBCXX20_CONSTEXPR _BIter partition(_BIter, _BIter, _Predicate); @@ -332,10 +339,12 @@ namespace std // 25.3, sorting and related operations: // 25.3.1, sorting: template + _GLIBCXX20_CONSTEXPR void sort(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void sort(_RAIter, _RAIter, _Compare); @@ -348,26 +357,32 @@ namespace std stable_sort(_RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void partial_sort(_RAIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void partial_sort(_RAIter, _RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR _RAIter partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR _RAIter partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void nth_element(_RAIter, _RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void nth_element(_RAIter, _RAIter, _RAIter, _Compare); @@ -490,34 +505,42 @@ namespace std // 25.3.6, heap operations: template + _GLIBCXX20_CONSTEXPR void push_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void push_heap(_RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void pop_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void pop_heap(_RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void make_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void make_heap(_RAIter, _RAIter, _Compare); template + _GLIBCXX20_CONSTEXPR void sort_heap(_RAIter, _RAIter); template + _GLIBCXX20_CONSTEXPR void sort_heap(_RAIter, _RAIter, _Compare); @@ -668,18 +691,22 @@ namespace std // 25.3.9, permutations template + _GLIBCXX20_CONSTEXPR bool next_permutation(_BIter, _BIter); template + _GLIBCXX20_CONSTEXPR bool next_permutation(_BIter, _BIter, _Compare); template + _GLIBCXX20_CONSTEXPR bool prev_permutation(_BIter, _BIter); template + _GLIBCXX20_CONSTEXPR bool prev_permutation(_BIter, _BIter, _Compare); } diff --git a/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc new file mode 100644 index 00000000000..f11271b7976 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/iter_swap/constexpr.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::iter_swap(ar0.begin() + 2, ar0.begin() + 5); + + return ok = ar0[2] == 5 && ar0[5] == 2; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc new file mode 100644 index 00000000000..1ce994ebf6a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/make_heap/constexpr.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array + ah{{0, + 1, 2, + 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}}; + + std::make_heap(ah.begin(), ah.begin() + 17); + ok = ok && std::is_heap(ah.begin(), ah.begin() + 17); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc new file mode 100644 index 00000000000..f463eddf934 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/next_permutation/constexpr.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::next_permutation(ar0.begin(), ar0.end()); + + return ok = ar0[11] == 10 && ar0[10] == 11; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc new file mode 100644 index 00000000000..2e20836ad38 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/nth_element/constexpr.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end()); + ok = ok && ar0[5] == 5; + + std::sort(ar0.begin(), ar0.end(), std::greater<>()); + std::nth_element(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>()); + ok = ok && ar0[5] == 6; + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc new file mode 100644 index 00000000000..e7d215981c0 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort/constexpr.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 7, 8, 9, 2, 3, 4, 5, 6, 10, 11}}; + + std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end()); + ok = ok && ar0[0] == 0 && ar0[4] == 4; + + std::partial_sort(ar0.begin(), ar0.begin() + 5, ar0.end(), std::greater<>()); + ok = ok && ar0[0] == 11 && ar0[4] == 7; + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc new file mode 100644 index 00000000000..94e6d2037d0 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/constexpr.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + const std::array ar0{{0, 7, 8, 9, 1, 2, 5, 6, 10, 3, 4, 11}}; + std::array or0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10, + or0.begin(), or0.begin() + 5); + + std::partial_sort_copy(ar0.begin() + 5, ar0.begin() + 10, + or0.begin(), or0.begin() + 5, std::greater<>()); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc new file mode 100644 index 00000000000..7f525951420 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/partition/constexpr.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{10, 0, 5, 1, 2, 6, 7, 8, 3, 4, 9, 11}}; + + auto iter1 = std::partition(ar0.begin(), ar0.end(), + [](int i){ return i < 7; }); + ok = ok && *iter1 == 8; + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc new file mode 100644 index 00000000000..d1e7f268626 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pop_heap/constexpr.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array + ah{{0, + 1, 2, + 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}}; + + std::make_heap(ah.begin(), ah.end()); + ok = ok && std::is_heap(ah.begin(), ah.end()); + + std::pop_heap(ah.begin(), ah.end()); + std::pop_heap(ah.begin(), ah.end() - 1); + std::pop_heap(ah.begin(), ah.end() - 2); + ok = ok && std::is_heap(ah.begin(), ah.end() - 3) + && !std::is_heap(ah.begin(), ah.end()); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc new file mode 100644 index 00000000000..55218e5bb73 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/constexpr.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::prev_permutation(ar0.begin(), ar0.end()); + + return ok = ar0[0] == 0; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc new file mode 100644 index 00000000000..ceb14ba6f0a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/push_heap/constexpr.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array + ah{{0, + 1, 2, + 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}}; + + std::make_heap(ah.begin(), ah.end() - 3); + ok = ok && std::is_heap(ah.begin(), ah.end() - 3); + + std::push_heap(ah.begin(), ah.end() - 2); + std::push_heap(ah.begin(), ah.end() - 1); + std::push_heap(ah.begin(), ah.end()); + ok = ok && std::is_heap(ah.begin(), ah.end()); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc new file mode 100644 index 00000000000..b55a9faf61e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/reverse/constexpr.cc @@ -0,0 +1,41 @@ +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::reverse(ar0.begin() + 2, ar0.begin() + 9); + + return ar0[2] == 8 && ar0[8] == 2; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc new file mode 100644 index 00000000000..dbdaac3cdd2 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/rotate/constexpr.cc @@ -0,0 +1,41 @@ +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + std::rotate(ar0.begin(), ar0.begin() + 5, ar0.end()); + + return ar0[0] == 5 && ar0[5] == 10; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc new file mode 100644 index 00000000000..732747302c9 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/sort/constexpr.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{10, 0, 1, 2, 5, 6, 7, 8, 3, 4, 9, 11}}; + + std::sort(ar0.begin(), ar0.end()); + ok = ok && std::is_sorted(ar0.begin(), ar0.end()); + + std::sort(ar0.begin(), ar0.end(), std::greater<>()); + ok = ok && std::is_sorted(ar0.begin(), ar0.end(), std::greater<>()); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc new file mode 100644 index 00000000000..8be490307ba --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/sort_heap/constexpr.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array + ah{{0, + 1, 2, + 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}}; + + std::make_heap(ah.begin(), ah.begin() + 17); + ok = ok && std::is_heap(ah.begin(), ah.begin() + 17); + + std::sort_heap(ah.begin(), ah.begin() + 17); + ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17); + + std::make_heap(ah.begin(), ah.begin() + 17, std::greater<>()); + ok = ok && std::is_heap(ah.begin(), ah.begin() + 17, std::greater<>()); + + std::sort_heap(ah.begin(), ah.begin() + 17, std::greater<>()); + ok = ok && std::is_sorted(ah.begin(), ah.begin() + 17, std::greater<>()); + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc new file mode 100644 index 00000000000..5e417810ad7 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/swap/constexpr.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + double asc = 3.1415; + double bsc = 2.7182; + std::swap(asc, bsc); + ok = ok && asc == 2.7182 && bsc == 3.1415; + + float arr[5]{0.0f, 1.0f, 2.0f, 3.0f, 4.0f}; + float brr[5]{5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + std::swap(arr, brr); + ok = ok && arr[2] == 7.0f && brr[2] == 2.0f; + + return ok; +} + +static_assert(test()); diff --git a/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc new file mode 100644 index 00000000000..2293e317bba --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/constexpr.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +#ifndef __cpp_lib_constexpr_swap_algorithms +# error "Feature-test macro for constexpr swap algorithms missing" +#elif __cpp_lib_constexpr_swap_algorithms < 201712L +# error "Feature-test macro for constexpr swap algorithms has wrong value" +#endif + +constexpr bool +test() +{ + auto ok = true; + + std::array ar0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + std::array ar1{{11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}}; + + const auto out01 = std::swap_ranges(ar0.begin(), ar0.begin() + 5, + ar1.begin() + 2); + + return ok = ar0[0] == 9 && ar1[2] == 0; +} + +static_assert(test());