18 Oct
2021
18 Oct
'21
1:22 a.m.
Andrey Semashev wrote:
Ok, let it be
template< typename T > inline typename enable_if< is_same< T, std::string_view >, std::string_view
::type api_function( T str ) { ... }
And now C++17 users are sad because when they call the function with a literal or a std::string it returns a boost::string_view, which they can't assign to a std:: string_view. You'd probably have them use a conversion function on each call. That's workable but does not exactly deliver the best user experience. No, the correct answer is that you write your own private string_view and use that. (Or tell your users to switch to C++23 I suppose.)