|
Boost : |
Subject: Re: [boost] [utility] string_ref construction from rvalue reference to string
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-08-03 08:55:59
On Sunday 03 August 2014 16:27:13 Andrey Davydov wrote:
> On Sat, Aug 2, 2014 at 2:46 AM, Nathan Crookston <nathan.crookston_at_[hidden]
> > wrote:
> >
> > I suppose that would break cases like:
> >
> > std::string getStr();
> > print(std::string_ref sr) { std::cout << sr << std::endl; }
> >
> > print(getStr());
> >
> > Causing people to have to write print(getStr().c_str()).
>
> It's possible to add `string_ref(reference_wrapper<const std::string>)`
> constructor to allow people write `print(boost::cref(getStr()))` instead of
> `print(getStr().c_str())`.
boost::reference_wrapper will not construct from rvalues as of 1.56.
std::reference_wrapper already doesn't. 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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk