From patchwork Sun Nov 17 01:33:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1196291 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-513815-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="t+azovFe"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="U8E3d7fm"; 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 47FvkF299Lz9sQp for ; Sun, 17 Nov 2019 12:33:41 +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=MfZ7WOkF2RDJJLp1IQQQaj90Eg0/XmUtJqDgSdl+dlHHMUVCW0+EO vKKWv0CIpWkOl82Ht65YvbYlaETMq4Kd69U1cYiIJnz9RJd0QApO04KoWbmGtfhn BlG5J13nV22JHGUdafmRwLgmUiEGNmN9hM6Du9LKdOqdOUuFpehxH4= 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=CZMuRwytCrVHUwJY2/+d4sfG7Z0=; b=t+azovFe5S1PUqUHz79C nURGmpXO+nxSjNuy7iGk8LCxiPLmNqYuFbUkx9x1NfImDrJyzJewtzAwwmF1uK6/ FZv/QxMJ8e4yEpTSJdF7lAyRX5LgvGpxOa5tNZrF2sBqFHLJakmHjjmuX5YrDMd1 rQzEh7b8GSIPB7P1XFeW/50= Received: (qmail 56581 invoked by alias); 17 Nov 2019 01:33:26 -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 56564 invoked by uid 89); 17 Nov 2019 01:33:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.2 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=__first, __last, 13016 X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 17 Nov 2019 01:33:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573954403; 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=jn2SruazMnj9dzBmxF93QGgD7QainCkjlmAaHFv79JM=; b=U8E3d7fmPqAKdQOIZCdk5x7503G9ox7NjhTDabA5Jvci8lgLUVvH1jLnAn9gSBKOgFGvAJ 5OnzV41o8+YhzNXHizqdeIygQ1jkH2b4qJqTgo0nEZp8rIhG1RhV1b8CtVA92YlCrI0vwp iDpaUcfwKkjFgi3iU0x9LoyC+1MjzAU= 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-52-bb4YE47pPziy6-xXX7dJAw-1; Sat, 16 Nov 2019 20:33:18 -0500 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 3071A8048E5; Sun, 17 Nov 2019 01:33:17 +0000 (UTC) Received: from localhost (unknown [10.33.36.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id D073A75E4B; Sun, 17 Nov 2019 01:33:16 +0000 (UTC) Date: Sun, 17 Nov 2019 01:33:17 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: add range constructor for std::string_view (P1391R4) Message-ID: <20191117013317.GA20202@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 * include/std/string_view (basic_string_view(It, End)): Add range constructor and deduction guide from P1391R4. * testsuite/21_strings/basic_string_view/cons/char/range.cc: New test. Tested powerpc64le-linux, committed to trunk. commit e0c554e4da7310df83bb1dcc7b8e6c4c9c5a2a4f Author: redi Date: Sun Nov 17 01:32:55 2019 +0000 libstdc++: add range constructor for std::string_view (P1391R4) * include/std/string_view (basic_string_view(It, End)): Add range constructor and deduction guide from P1391R4. * testsuite/21_strings/basic_string_view/cons/char/range.cc: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@278371 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index ff1c0c3f36f..9d2a8e8e0c2 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -130,6 +130,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_len{__len}, _M_str{__str} { } +#if __cplusplus > 201703L && __cpp_lib_concepts + template _End> + requires same_as, _CharT> + && (!convertible_to<_End, size_type>) + constexpr + basic_string_view(_It __first, _End __last) + : _M_len(__last - __first), _M_str(std::to_address(__first)) + { } +#endif + constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default; @@ -457,6 +467,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _CharT* _M_str; }; +#if __cplusplus > 201703L && __cpp_lib_concepts && __cpp_deduction_guides + template _End> + basic_string_view(_It, _End) -> basic_string_view>; +#endif + // [string.view.comparison], non-member basic_string_view comparison function // Several of these functions use type_identity_t to create a non-deduced diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.cc new file mode 100644 index 00000000000..d554b77c874 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range.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 run { target c++2a } } + +#include +#include +#include + +constexpr char str[] = "abcdefg"; +constexpr std::basic_string_view s(std::begin(str), std::cend(str) - 1); +static_assert( s == str ); +static_assert( s.data() == str ); + +void +test01() +{ + std::vector v{'a', 'b', 'c'}; + std::basic_string_view s(v.begin(), v.end()); + VERIFY( s.data() == v.data() ); +} + +int +main() +{ + test01(); +}