Is there sense in using const std::string& arguments in C++17?

前端 未结 1 824
南笙
南笙 2021-02-11 18:16

By getting string_view in C++17 we got cheap method of passing both std::string and char* to functions that do not take ownership of the s

相关标签:
1条回答
  • 2021-02-11 18:36

    Yes.

    The problem with std::string_view is that it doesn't remember if it points to a null-terminated string or not.

    If you're writing a wrapper for a C api that uses null-terminated strings, you would have to constantly copy your std::string_views into std::strings to make sure you have null-terminators.

    0 讨论(0)
提交回复
热议问题