Boost logo

Boost :

Subject: Re: [boost] [utility] string_ref construction from rvalue reference to string
From: Andrey Davydov (andrey.a.davydov_at_[hidden])
Date: 2014-08-03 09:28:25


On Sun, Aug 3, 2014 at 4:55 PM, Andrey Semashev <andrey.semashev_at_[hidden]>
wrote:

> boost::reference_wrapper will not construct from rvalues as of 1.56.
> std::reference_wrapper already doesn't.

OK, it's possible to write custom function

    template<class charT, class traits, class Allocator>
    basic_string_ref<charT, traits>
unsafe_make_ref(std::basic_string<charT, traits, Allocator> && str)
    {
        return { str };
    }

and use it.

Even then, IMHO string_ref should not
> require these tricks, it should work transparently. I'm ok with leaving it
> vulnerable to incorrect use if it's not possible to protect it without
> sacrificing usability.
>

I'm not sure that one extra call [`print(unsafe_make_ref(getStr()))`
instead of `print(getStr())`] is too high usability price for the safety in
common case. Of course, it's only IMHO.

-- 
Andrey

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk