apache / apache/brpc

Make StringPiece match std::string_view

Open
#1,238 5 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**

C++17 will include `std::string_view`, which is essentially just a standardized replacement for StringPiece. To plan ahead for this, we should consider updating the StringPiece API so that it exactly matches std::string_view. Then a few years from now when C++17 is widespread we can make StringPiece just a type alias for std::string_view. I believe StringPiece is just used within protobuf internals at the moment and so we can safely change its API without breaking any user code.

**Describe the solution you'd like (描述你期望的解决方法)**

Using a macro to using string_view

```
#ifdef XXX
using base = basic_string_view
...
#else
// The original definitions..
#endif
```

The abseil and boost solve it in this way.

**Describe alternatives you've considered (描述你想到的折衷方案)**

Using constructor like `StringPiece(string_view)`...

**Additional context/screenshots (更多上下文/截图)**

None.

Contributor guide

Open the contributing guide

Research direction

No file or test is named. Start by locating the StringPiece implementation and its internal usages, then compare its API with C++17 std::string_view and review the proposed macro-based compatibility approach. Done means the supported StringPiece API matches std::string_view closely enough for a future type alias without breaking current internal use.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.