From patchwork Thu Oct 31 21:42:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1187680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512199-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="veix4zBN"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="VFMICVzZ"; 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 473zMF1Zp6z9sP4 for ; Fri, 1 Nov 2019 08:42:46 +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=qmNAFBrIPBqvGO8jfW9O2v5ag2R8NYg7pEaYPrZeGQJDf6LGoegTn AlgK2RRsxUP/H0wxvFmxWk7akGV3U6s5cHqpwjVjWoXX7bowvgvkJexEO5nAgfXP FhVGuaZnfD0nLXhufVW13hlHbobM7Xqc4/UUC6qGU3t1KwnHISqbZQ= 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=fVFjBE6R1Tv/Ox/gPr79SDHpiGE=; b=veix4zBNh/aJNx407K3s RQEaWTU85AisTiwVYmvzuOx0DssTMvOYjjYkEuDc8xqukC2butRXtuVd/1Ie+ZPo NMa6Knmv7SpYn5JihQys08HmwyjBO8NOAxfn+zAOEFvCxxoAFP3w2mqUDC+W8M1d QRnhpoKLDKrM8flyh+4T5aQ= Received: (qmail 78914 invoked by alias); 31 Oct 2019 21:42:23 -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 78839 invoked by uid 89); 31 Oct 2019 21:42:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=unavailable version=3.3.1 spammy=sk:input_i, 201103l, 201103L, sk:iter_re X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 Oct 2019 21:42:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572558135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=v7dmGkmt8gTu3FBSANeeyROF30PDW0HUflnflwFpiRw=; b=VFMICVzZj4iOuRDLNTf6ouhXV3j/VDoKJIt/MdQgT1jMDvPa6Bi7jJ9hNXsxNpFNLLjute XBetYyMnHtsYsK68llG19vBq7rowNvSMtXywkWi3UA9p74cfvQoMXN8BjTF4O6A98MJO19 nSeQDdP8M6Eyrl2sZUuPCWp72i0mGPs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-O0tQVAxCNSaKLnV2AOZkeQ-1; Thu, 31 Oct 2019 17:42:11 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C394107ACC0; Thu, 31 Oct 2019 21:42:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id E52685C290; Thu, 31 Oct 2019 21:42:09 +0000 (UTC) Date: Thu, 31 Oct 2019 21:42:09 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Partial implementation of C++20 of header Message-ID: <20191031214209.GA4314@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.12.1 (2019-06-15) X-Mimecast-Spam-Score: 0 Content-Disposition: inline * doc/doxygen/user.cfg.in: Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Include new header. * include/std/ranges: New header. (ranges::sentinel_t, ranges::range_value_t, ranges::range_reference_t) (ranges::range_rvalue_reference_t, ranges::sized_range) (ranges::output_range, ranges::input_ranges, ranges::forward_range) (ranges::bidirectional_range, ranges::random_access_range) (ranges::contiguous_range, ranges::common::range): Define. * testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: Check that disabled_sized_sentinel can be specialized. * testsuite/std/ranges/access/begin.cc: Include instead of . * testsuite/std/ranges/access/cbegin.cc: Likewise. * testsuite/std/ranges/access/cdata.cc: Likewise. * testsuite/std/ranges/access/cend.cc: Likewise. * testsuite/std/ranges/access/crbegin.cc: Likewise. * testsuite/std/ranges/access/crend.cc: Likewise. * testsuite/std/ranges/access/data.cc: Likewise. * testsuite/std/ranges/access/empty.cc: Likewise. * testsuite/std/ranges/access/end.cc: Likewise. * testsuite/std/ranges/access/end_neg.cc: Likewise. * testsuite/std/ranges/access/rbegin.cc: Likewise. * testsuite/std/ranges/access/rend.cc: Likewise. * testsuite/std/ranges/access/size.cc: Likewise. * testsuite/std/ranges/access/size_neg.cc: Likewise. * testsuite/std/ranges/headers/ranges/synopsis.cc: New test. * testsuite/std/ranges/range.cc: New test. * testsuite/std/ranges/refinements.cc: New test. * testsuite/std/ranges/sized.cc: New test. * testsuite/util/testsuite_iterators.h: Add aliases for range types. (output_iterator_wrapper::WritableObject::operator=): Add const qualifier so that output_iterator_wrapper satisfies writable. I have lots more of this header written, but I need to finish writing the tests. This is a start. Tested powerpc64le-linux, committed to trunk. commit 30d052cfd06792c8c317b69129b5ca9031b90391 Author: Jonathan Wakely Date: Thu Oct 31 19:42:03 2019 +0000 Partial implementation of C++20 of header * doc/doxygen/user.cfg.in: Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Include new header. * include/std/ranges: New header. (ranges::sentinel_t, ranges::range_value_t, ranges::range_reference_t) (ranges::range_rvalue_reference_t, ranges::sized_range) (ranges::output_range, ranges::input_ranges, ranges::forward_range) (ranges::bidirectional_range, ranges::random_access_range) (ranges::contiguous_range, ranges::common::range): Define. * testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: Check that disabled_sized_sentinel can be specialized. * testsuite/std/ranges/access/begin.cc: Include instead of . * testsuite/std/ranges/access/cbegin.cc: Likewise. * testsuite/std/ranges/access/cdata.cc: Likewise. * testsuite/std/ranges/access/cend.cc: Likewise. * testsuite/std/ranges/access/crbegin.cc: Likewise. * testsuite/std/ranges/access/crend.cc: Likewise. * testsuite/std/ranges/access/data.cc: Likewise. * testsuite/std/ranges/access/empty.cc: Likewise. * testsuite/std/ranges/access/end.cc: Likewise. * testsuite/std/ranges/access/end_neg.cc: Likewise. * testsuite/std/ranges/access/rbegin.cc: Likewise. * testsuite/std/ranges/access/rend.cc: Likewise. * testsuite/std/ranges/access/size.cc: Likewise. * testsuite/std/ranges/access/size_neg.cc: Likewise. * testsuite/std/ranges/headers/ranges/synopsis.cc: New test. * testsuite/std/ranges/range.cc: New test. * testsuite/std/ranges/refinements.cc: New test. * testsuite/std/ranges/sized.cc: New test. * testsuite/util/testsuite_iterators.h: Add aliases for range types. (output_iterator_wrapper::WritableObject::operator=): Add const qualifier so that output_iterator_wrapper satisfies writable. diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in index 3c0295d99a5..42001016721 100644 --- a/libstdc++-v3/doc/doxygen/user.cfg.in +++ b/libstdc++-v3/doc/doxygen/user.cfg.in @@ -829,6 +829,7 @@ INPUT = @srcdir@/doc/doxygen/doxygroups.cc \ include/ostream \ include/queue \ include/random \ + include/ranges \ include/ratio \ include/regex \ include/scoped_allocator \ diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 401c87ad103..3e526dc14b7 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -64,6 +64,7 @@ std_headers = \ ${std_srcdir}/ostream \ ${std_srcdir}/queue \ ${std_srcdir}/random \ + ${std_srcdir}/ranges \ ${std_srcdir}/ratio \ ${std_srcdir}/regex \ ${std_srcdir}/scoped_allocator \ diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index fefd6e76845..57c3e2e32ee 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -138,7 +138,7 @@ // #include #include #include -// #include +#include #include // #include #include diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges new file mode 100644 index 00000000000..884fa1d1408 --- /dev/null +++ b/libstdc++-v3/include/std/ranges @@ -0,0 +1,112 @@ +// -*- C++ -*- + +// 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received __a copy of the GNU General Public License and +// __a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file include/ranges + * This is a Standard C++ Library header. + * @ingroup concepts + */ + +#ifndef _GLIBCXX_RANGES +#define _GLIBCXX_RANGES 1 + +#if __cplusplus > 201703L + +#pragma GCC system_header + +#include + +#if __cpp_lib_concepts + +#include + +/** + * @defgroup ranges Ranges + * + * Components for dealing with ranges of elements. + */ + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION +namespace ranges +{ + // [range.range] The range concept. + // Defined in + // template concept range; + + template + using sentinel_t = decltype(ranges::end(std::declval<_Range&>())); + + template + using range_value_t = iter_value_t>; + + template + using range_reference_t = iter_reference_t>; + + template + using range_rvalue_reference_t + = iter_rvalue_reference_t>; + + // [range.sized] The sized_range concept. + // Defined in + // template concept sized_range; + + // [range.refinements] + + template + concept output_range + = range<_Range> && output_iterator, _Tp>; + + template + concept input_range = range<_Tp> && input_iterator>; + + template + concept forward_range + = input_range<_Tp> && forward_iterator>; + + template + concept bidirectional_range + = forward_range<_Tp> && bidirectional_iterator>; + + template + concept random_access_range + = bidirectional_range<_Tp> && random_access_iterator>; + + template + concept contiguous_range + = random_access_range<_Tp> && contiguous_iterator> + && requires(_Tp& __t) + { + { ranges::data(__t) } -> same_as>>; + }; + + template + concept common_range + = range<_Tp> && same_as, sentinel_t<_Tp>>; +} // namespace ranges +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace +#endif // library concepts +#endif // C++2a +#endif /* _GLIBCXX_RANGES */ diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc index 2dbfb767fdb..824b0b4f38c 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc @@ -78,6 +78,9 @@ namespace std struct unreachable_sentinel_t; } +struct I { }; +template<> constexpr bool std::disable_sized_sentinel = true; + namespace __gnu_test { // customization points diff --git a/libstdc++-v3/testsuite/std/ranges/access/begin.cc b/libstdc++-v3/testsuite/std/ranges/access/begin.cc index 100dcf69c6e..e4c245a76bb 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/begin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/begin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc index 34dd7fec3c6..54db3658896 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include using std::same_as; diff --git a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc index 9a1ab5b9607..b16c99607a5 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include void diff --git a/libstdc++-v3/testsuite/std/ranges/access/cend.cc b/libstdc++-v3/testsuite/std/ranges/access/cend.cc index 94349c35d51..3b57b3dbcaf 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include using std::same_as; diff --git a/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc index 24939ac658e..d9e5b0cbef7 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/crend.cc b/libstdc++-v3/testsuite/std/ranges/access/crend.cc index ef0fb0e6b09..e56491973b2 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/crend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/crend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/data.cc b/libstdc++-v3/testsuite/std/ranges/access/data.cc index d9129d055fc..49321640182 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/data.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/data.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/empty.cc b/libstdc++-v3/testsuite/std/ranges/access/empty.cc index 64b1e1b5e1b..9d6aa282142 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/empty.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/empty.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/end.cc b/libstdc++-v3/testsuite/std/ranges/access/end.cc index 6638bb35721..ed269c5433f 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/end.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/end.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc b/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc index a2a8fb05f92..0b40d274567 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do compile { target c++2a } } -#include // N.B. should be +#include extern int unbounded[]; diff --git a/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc index 6cfc1a38122..067ddd7ced6 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/rend.cc b/libstdc++-v3/testsuite/std/ranges/access/rend.cc index 2192825708a..17caa9fb31a 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/rend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/rend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/size.cc b/libstdc++-v3/testsuite/std/ranges/access/size.cc index b0a27ca2a87..6e9af7942ec 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/size.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/size.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc b/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc index 0ba8d81874f..65fce104ff6 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do compile { target c++2a } } -#include // N.B. should be +#include extern int unbounded[]; diff --git a/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc new file mode 100644 index 00000000000..d4596cc8db5 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc @@ -0,0 +1,38 @@ +// 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 + +struct R { }; +template<> constexpr bool std::ranges::disable_sized_range = true; + +namespace __gnu_test +{ + constexpr const bool* disable_sized_range + = &std::ranges::disable_sized_range; + constexpr auto* begin = &std::ranges::begin; + constexpr auto* end = &std::ranges::end; + constexpr auto* cbegin = &std::ranges::cbegin; + constexpr auto* cend = &std::ranges::cend; + constexpr auto* rbegin = &std::ranges::rbegin; + constexpr auto* rend = &std::ranges::rend; + constexpr auto* crbegin = &std::ranges::crbegin; + constexpr auto* crend = &std::ranges::crend; +} diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc b/libstdc++-v3/testsuite/std/ranges/range.cc new file mode 100644 index 00000000000..44869de3ffb --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/range.cc @@ -0,0 +1,89 @@ +// 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 + +static_assert( std::ranges::range ); +static_assert( std::ranges::range ); +static_assert( std::ranges::range ); +static_assert( !std::ranges::range ); + +using namespace __gnu_test; + +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); + +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); + +using std::same_as; + +using C = test_contiguous_range; +using I = test_input_range; +using O = test_output_range; + +static_assert( same_as, + contiguous_iterator_wrapper> ); +static_assert( same_as, + decltype(std::declval().begin())> ); + +static_assert( same_as, + contiguous_iterator_wrapper> ); +static_assert( same_as, + decltype(std::declval().end())> ); + +static_assert( same_as, + std::ptrdiff_t> ); +static_assert( same_as, + std::ptrdiff_t> ); + +static_assert( same_as, + char> ); + +static_assert( same_as, + char&> ); +static_assert( same_as, + WritableObject> ); + +static_assert( same_as, + char&&> ); +static_assert( same_as, + WritableObject> ); diff --git a/libstdc++-v3/testsuite/std/ranges/refinements.cc b/libstdc++-v3/testsuite/std/ranges/refinements.cc new file mode 100644 index 00000000000..0b315397944 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/refinements.cc @@ -0,0 +1,79 @@ +// 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 + +static_assert( std::ranges::output_range ); +static_assert( ! std::ranges::output_range ); +static_assert( std::ranges::output_range ); +static_assert( ! std::ranges::output_range ); + +static_assert( std::ranges::input_range ); +static_assert( std::ranges::input_range ); +static_assert( std::ranges::input_range ); + +static_assert( std::ranges::contiguous_range ); +static_assert( std::ranges::contiguous_range ); +static_assert( std::ranges::contiguous_range ); + +using namespace __gnu_test; + +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( ! std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); + +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( ! std::ranges::input_range> ); + +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( ! std::ranges::forward_range> ); +static_assert( ! std::ranges::forward_range> ); + +static_assert( std::ranges::bidirectional_range> ); +static_assert( std::ranges::bidirectional_range>); +static_assert( std::ranges::bidirectional_range>); +static_assert( ! std::ranges::bidirectional_range> ); +static_assert( ! std::ranges::bidirectional_range> ); +static_assert( ! std::ranges::bidirectional_range> ); + +static_assert( std::ranges::random_access_range> ); +static_assert( std::ranges::random_access_range>); +static_assert( ! std::ranges::random_access_range>); +static_assert( ! std::ranges::random_access_range> ); +static_assert( ! std::ranges::random_access_range> ); +static_assert( ! std::ranges::random_access_range> ); + +static_assert( std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range>); +static_assert( ! std::ranges::contiguous_range>); +static_assert( ! std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range> ); diff --git a/libstdc++-v3/testsuite/std/ranges/sized.cc b/libstdc++-v3/testsuite/std/ranges/sized.cc new file mode 100644 index 00000000000..dd685c7a674 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/sized.cc @@ -0,0 +1,75 @@ +// 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 + +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); +static_assert( !std::ranges::sized_range ); + +using namespace __gnu_test; + +// ranges::size(r) uses (end(r) - begin(r)) +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +// ranges::size(r) is invalid, (end(r) - begin(r)) requires sized sentinel +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); + +// ranges::size(r) uses r.size() +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); + +using long_range = __gnu_test::test_random_access_sized_range; +template<> constexpr bool std::ranges::disable_sized_range = true; + +// Despite being disabled, this is still a sized_range because ranges::size(r) +// works, by using (ranges::end(r) - ranges::begin(r)). +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); + +using short_range = __gnu_test::test_bidirectional_sized_range; +template<> constexpr bool std::ranges::disable_sized_range = true; + +// This is not a sized range because ranges::size(r) cannot use member size, +// or ADL size, and (ranges::end(r) - ranges::begin(r)) is ill-formed for +// bidirectional iterators. +static_assert( !std::ranges::sized_range ); +static_assert( !std::ranges::sized_range ); diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index c5ae5b123fe..d20257c1b31 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -95,7 +95,7 @@ namespace __gnu_test #if __cplusplus >= 201103L template typename std::enable_if::value>::type - operator=(U&& new_val) + operator=(U&& new_val) const { ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); SharedInfo->writtento[ptr - SharedInfo->first] = 1; @@ -720,6 +720,25 @@ namespace __gnu_test typename Iter::ContainerType bounds; }; + template + using test_contiguous_range + = test_range; + template + using test_random_access_range + = test_range; + template + using test_bidirectional_range + = test_range; + template + using test_forward_range + = test_range; + template + using test_input_range + = test_range; + template + using test_output_range + = test_range; + // A type meeting the minimum std::sized_range requirements template class Iter> struct test_sized_range : test_range @@ -729,6 +748,25 @@ namespace __gnu_test std::size_t size() const noexcept { return this->bounds.size(); } }; + + template + using test_contiguous_sized_range + = test_sized_range; + template + using test_random_access_sized_range + = test_sized_range; + template + using test_bidirectional_sized_range + = test_sized_range; + template + using test_forward_sized_range + = test_sized_range; + template + using test_input_sized_range + = test_sized_range; + template + using test_output_sized_range + = test_sized_range; #endif // C++20 } // namespace __gnu_test #endif // _TESTSUITE_ITERATORS