This is an archive of the discontinued LLVM Phabricator instance.

[ADT] add StringViewExtras llvm::starts_with for std::string_view
ClosedPublic

Authored by nickdesaulniers on Apr 14 2023, 12:30 PM.

Details

Summary

std::string_view::starts_with isn't available until C++20. Create
llvm::starts_with for now; we can delete this when LLVM moves to C++20
one day.

To run the newly added unit test:
$ cd llvm/build; ninja ADTTests; cd -
$ ./llvm/build/unittests/ADT/ADTTests --gtest_filter=StringViewExtrasTest.\*

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 12:30 PM
nickdesaulniers requested review of this revision.Apr 14 2023, 12:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 12:30 PM
  • fix comment in new header
nickdesaulniers edited the summary of this revision. (Show Details)
  • update description on how to run new unit tests
erichkeane added inline comments.Apr 14 2023, 12:35 PM
llvm/include/llvm/ADT/StringViewExtras.h
25

This might be a bit noisy depending on how compilers/libraries define this in C++17 mode. We might want a __cplusplus > (whatever the 2020 value is) here as well.

llvm/unittests/ADT/StringViewExtrasTest.cpp
23

Why is this running this 2x in a row?

nickdesaulniers marked 2 inline comments as done.
  • remove test duplication, remove warning
llvm/include/llvm/ADT/StringViewExtras.h
25

Yeah, I'll just remove it.

erichkeane accepted this revision.Apr 14 2023, 1:19 PM
This revision is now accepted and ready to land.Apr 14 2023, 1:19 PM
MaskRay accepted this revision.Apr 14 2023, 1:19 PM
This revision was landed with ongoing or failed builds.Apr 14 2023, 1:47 PM
This revision was automatically updated to reflect the committed changes.