C++ Logo

std-proposals

Advanced search

Re: Named return values revival

From: Phil Bouchard <boost_at_[hidden]>
Date: Mon, 29 Mar 2021 09:31:40 -0400
On 3/29/21 5:42 AM, Magnus Fromreide via Std-Proposals wrote:
> On Sun, Mar 28, 2021 at 11:18:51PM -0400, Phil Bouchard via Std-Proposals wrote:
>>
>> #include <string>
>>
>> namespace personal
>> {
>> struct string : std::wstring
>> {
>> typedef std::wstring base;
>> [...]
>>
>> char const * encoded_c_str() [std::string && r = std::string()]
>> {
>> r = std::string(base::begin(), base::end());
>>
>> return r.c_str();
>> }
>> };
>> }
>>
>> personal::string s = "Hello world";
>>
>> cout << s.encoded_c_str() << endl; // will be just fine
> In what way does that differ from
>
> const char* encoded_c_str(std::string& r = std::string())
> {
> r = std::string(base::begin(), base::end());
> return r.c_str();
> }
>
> (Yes, I am aware that this code rightfully will result in a warning from
> current compilers but it still looks suspiciosly similar to your proposal)
>
> /MF

Well you can't pass an r-value using a non-const reference in general.

-- 
*Phil Bouchard*
Founder & CTO
C.: (819) 328-4743
Fornux Logo <http://www.fornux.com>

Received on 2021-03-29 08:31:47