|
Boost : |
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2021-10-18 11:11:38
On 10/18/21 4:26 AM, Peter Dimov via Boost wrote:
> Andrey Semashev wrote:
>>> How would that work, exactly? Take the example function signature and
>>> show us how it's done.
>>
>> boost::string_view get_string();
>>
>> template< typename String >
>> String get_string()
>> {
>> boost::string_view res = get_string();
>> return String(res.data(), res.size());
>> }
>
> The function is
>
> boost::string_view api_function( boost::string_view str );
The code I posted was an illustration of the case when you don't accept
a string in the function.
> If we apply the technique above,
>
> api_function( "something" );
>
> will return boost::string_view, and C++17 users will have the option
> of using
>
> auto r = api_function<std::string_view>( "something" );
>
> Again, this works, but isn't exactly optimal. C++17 users are penalized
> for no good reason.
If you want to make std::string_view the default, you can do exactly
that using the same approach. Automatically or by user defining a macro.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk