Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::string_view support #906

Merged
merged 3 commits into from
Jun 24, 2017
Merged

std::string_view support #906

merged 3 commits into from
Jun 24, 2017

Conversation

jagerman
Copy link
Member

This PR adds support for std::string_view (and related, e.g. std::u16string_view) by making the current std::string caster slightly more generic so that it can support both std::strings and std::string_views.

It also includes commits that update the strings.rst documentation with style fixes (wrapping, trailing whitespace removal) to the strings.rst documentation, and one minor wording fix. (They don't really have anything to do with the PR aside from me noticing them when writing it).

Fixes #905

I've added the <string_view> include for this directly in cast.h rather than push it into stl.h: both stdlibc++ and libc++ already #include <string_view> as an implementation detail of #include <string> when compiling in C++17 mode, so the extra header isn't actually pulling in more STL code in practice.

Copy link
Member

@dean0x7d dean0x7d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition! Including it directly in cast.h seems fine to me. Considering that std::string has both a std::string_view converting constructor and an operator std::string_view(), it's a safe bet that it's going in by default with #include <string>.

@@ -116,6 +116,10 @@ as arguments and return values, refer to the section on binding :ref:`classes`.
+------------------------------------+---------------------------+-------------------------------+
| ``std::wstring`` | STL dynamic wide string | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::string_view``, | STL C++17 string views | :file:`pybind11/pybind11.h` |
| ``std::u16string_view``, | (only available when | |
| etc. | compiling in C++17 mode) | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the text in parentheses is necessary. Just mentioning C++17 is enough.

@jagerman jagerman merged commit f42af24 into pybind:master Jun 24, 2017
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
@jagerman jagerman deleted the string-view branch August 14, 2017 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: std::string_view support
2 participants