From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129875 invoked by alias); 18 Mar 2018 00:11:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 129865 invoked by uid 89); 18 Mar 2018 00:10:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 18 Mar 2018 00:10:58 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w2I0ApDO016802 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 17 Mar 2018 20:10:56 -0400 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8B48D1E4AE for ; Sat, 17 Mar 2018 20:10:51 -0400 (EDT) Subject: Re: [PATCH 2/2] Add gdb::string_view To: gdb-patches@sourceware.org References: <20180317234902.18278-1-simon.marchi@polymtl.ca> <20180317234902.18278-2-simon.marchi@polymtl.ca> From: Simon Marchi Message-ID: <2d68023c-7f24-7eb5-2822-00815b41ba2a@polymtl.ca> Date: Sun, 18 Mar 2018 00:11:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180317234902.18278-2-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sun, 18 Mar 2018 00:10:51 +0000 X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00344.txt.bz2 On 2018-03-17 19:49, Simon Marchi wrote: > We had a few times the need for a data structure that does essentially > what C++17's std::string_view does, which is to give an std::string-like > interface (only the read-only operations) to an arbitrary character > buffer. > > I first copied the string_view file from today's gcc master > (b427286632d7) and adapted it (I don't think there should be any legal > issues since the copyright should already belong to the FSF): > > - I removed things related to wstring_view, u16string_view and > u32string_view (I don't think we need them, but we can always add them > later). > - I removed usages of _GLIBCXX_BEGIN_NAMESPACE_VERSION and > _GLIBCXX_END_NAMESPACE_VERSION. > - I put the code in the gdb namespace. I had to add a few "std::" in front of > std type usages. > - I added a constructor that builds a string_view from an std::string, > so that we can pass strings to string_view parameters seamlessly. > Normally, that's handled by "operator __sv_type" in the std::string > declaration, but it only exists when building with c++17. > - When building with >= c++17, gdb::string_view is an alias of > std::string_view. > > The result is close enough to the original file that if we ever need to > update it, it should be easy enough to compare it with the new version > in a diff editor and merge the new changes in. Hmm, when building with older g++ (such as the aarch64 builders on the buildbot, which have g++ 4.8), it trips on: using __idt = std::common_type_t<_Tp>; It looks like that release of g++ didn't have std::common_type_t. I guess it would be possible to avoid using it, and change these: operator==(basic_string_view<_CharT, _Traits> __x, __detail::__idt> __y) noexcept for operator==(basic_string_view<_CharT, _Traits> __x, basic_string_view<_CharT, _Traits> __y) noexcept but I am not aware of what consequences it would have. Simon