[Xapian-tickets] [Xapian] #785: Use std::string_view whenever possible
Xapian
nobody at xapian.org
Sat May 4 11:33:10 BST 2019
#785: Use std::string_view whenever possible
-------------------------+-------------------------
Reporter: Kronuz | Owner: olly
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Other | Version:
Severity: normal | Resolution:
Keywords: | Blocked By:
Blocking: | Operating System: All
-------------------------+-------------------------
Comment (by Kronuz):
We could start by exposing an API which receives `const char*, size_t`
instead of `const std::string&`, and internally try passing/using only
functions receiving the former. Afterwards, adding support for string
views is a matter of just exposing APIs that convert the string view to
`const char*, size_t`:
{{{
void api_method(const char*, size_t);
void api_method(std::string_view arg) {
api_method(arg.data(), arg.size());
}
}}}
Or we can create our own std::string_view (a mere wrapper maybe, when the
real thing is available). String views are in basically that: `const
char*, size_t` (or rather, actually, `const char* begin, const char* end`.
String views have its quirks and at times get tricky, but the essence is
at the end not constructing strings out of substrings.
--
Ticket URL: <https://trac.xapian.org/ticket/785#comment:2>
Xapian <https://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list