This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Adds string_view constructor overload
ClosedPublic

Authored by Mordante on Jun 17 2023, 9:33 AM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Commits
rGea82a822d990: [libc++] Adds string_view constructor overload
Summary

Implements

  • P2697R1 Interfacing bitset with string_view

Depends on D153192

Diff Detail

Event Timeline

Mordante created this revision.Jun 17 2023, 9:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2023, 9:33 AM
Herald added a subscriber: arichardson. · View Herald Transcript
Mordante requested review of this revision.Jun 17 2023, 9:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2023, 9:33 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante updated this revision to Diff 532457.Jun 18 2023, 2:58 AM

CI fixes.

Mordante updated this revision to Diff 532463.Jun 18 2023, 3:32 AM

Updates transitive includes.

Mordante updated this revision to Diff 532465.Jun 18 2023, 3:50 AM

Rebased on parent.

philnik added a subscriber: philnik.Jul 7 2023, 4:43 PM
philnik added inline comments.
libcxx/include/bitset
845

Given that we want to move away from defining member functions out-of-line, maybe we want to jut define the new functions inline directly?

854–868

I think a helper to deduplicate this code between the overloads above and below wold be a good idea. There is also some pretty obvious optimization opportunity missed by clang for this code, so maybe we can improve on it later.

Mordante updated this revision to Diff 538352.Jul 8 2023, 4:31 AM

Rebased and update version number in status tables.

Mordante planned changes to this revision.Jul 8 2023, 4:31 AM

Thanks for the review!

libcxx/include/bitset
845

Do we? I must have missed that message. When/where was this discussed? (I'm not objecting against it.)

854–868

I really dislike that idea in this patch. I'll create a different patch to do the refactoring first.

philnik added inline comments.Jul 10 2023, 8:06 AM
libcxx/include/bitset
845

I don't think we ever discussed this explicitly, but that's how we write every new class, so I don't see why that would be different for pre-existing classes. So I guess I'm assuming consensus on this based on how people write code.

Mordante updated this revision to Diff 541710.Jul 18 2023, 1:34 PM

Addresses review comments.

Mordante marked 3 inline comments as done.Jul 18 2023, 1:36 PM
Mordante added inline comments.
libcxx/include/bitset
845

I see. I don't object so I inlined the new constructor too.

Mordante updated this revision to Diff 549588.Aug 12 2023, 3:35 AM
Mordante marked an inline comment as done.

Rebased and target LLVM-18 as shipping vehicle.

ldionne accepted this revision.Aug 22 2023, 10:33 AM
ldionne added a subscriber: ldionne.

Thanks! LGTM w/ test comments applied.

libcxx/include/bitset
42–46

Maybe this is more explicit?

template <class charT>
        constexpr explicit bitset(const charT* str,
            typename basic_string<charT>::size_type n = basic_string<charT>::npos,
            charT zero = charT('0'), charT one = charT('1'));                                // until C++26, constexpr since C++23

template <class charT>
        constexpr explicit bitset(const charT* str,
            typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
            charT zero = charT('0'), charT one = charT('1'));                                // since C++26
libcxx/test/std/utilities/template.bitset/bitset.cons/string_view_ctor.pass.cpp
1

We need to add stricter tests for the default arguments. Specifically, we should be calling as

bitset(s)
bitset(s, pos)
bitset(s, pos, n)
bitset(s, pos, n, zero)
bitset(s, pos, n, zero, one)

Also, it would be great to backport these additional tests to the string and c-string constructors, since it'll be trivial to do that. I'd do it as a fly-by change in this patch.

3

We are also not testing for the explicit-ness of the constructor. We can using the !is_convertible && is_constructible check.

This revision is now accepted and ready to land.Aug 22 2023, 10:33 AM
Mordante updated this revision to Diff 553372.Aug 24 2023, 11:14 PM

Rebased and addresses review comments

Mordante marked 3 inline comments as done.Aug 25 2023, 8:55 AM
This revision was landed with ongoing or failed builds.Aug 25 2023, 8:56 AM
This revision was automatically updated to reflect the committed changes.