
On 10/18/21 3:57 AM, Vinnie Falco wrote:
On Sun, Oct 17, 2021 at 5:47 PM Andrey Semashev via Boost
wrote: Making your libraries explicitly support std::string_view, in addition to boost::string_view, is one option.
Do you perhaps have some example code to share? Peter gave a function signature:
The scenario being addressed here is that of a Boost library that does not require C++17, yet its users want to use std::string_view when interacting with the library. That is, the library API is
boost::string_view api_function( boost::string_view str );
What would this look like with "explicitly supporting std::string_view in addition to boost::string_view" ?
Add an overload like this: #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) inline std::string_view api_function( std::string_view str ) { boost::string_view res = api_function( boost::string_view(str.data(), str.size())); return std::string_view(res.data(), res.size()); } #endif Of course, make helper functions to convert between the string_views. And, as I said, have a convention in case if you don't take a string_view as an argument.