This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] Add gdb::string_view


On 03/18/2018 12:10 AM, Simon Marchi wrote:
> 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.

Great, I've been wanting to do something like this for a while.

>>
>> 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:

It has std::common_type though.  C++14 std::foo_t types are usually just a
helper/convenience alias template, like:

  /// Alias template for common_type
  template<typename... _Tp>
    using common_type_t = typename common_type<_Tp...>::type;

So it sounds like we can just use the C++11 / ::type form directly, or
add gdb::common_type_t somewhere, like common/traits.h or to our
copy of string_view.

> 
>     operator==(basic_string_view<_CharT, _Traits> __x,
>                __detail::__idt<basic_string_view<_CharT, _Traits>> __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.

Would it be possible to import some of the libstdc++'s relevant
testscases into our unit tests framework, like was done for
gdb::optional [1]?

[1] https://sourceware.org/ml/gdb-patches/2017-04/msg00239.html

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]