[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost
Subject:    [boost] [utility] string_ref construction from rvalue reference to string
From:       Андрей Давыдов <andrey.a.davydov () gmail ! com>
Date:       2014-07-31 7:53:47
Message-ID: CAN1iZb52POcLJBXqxkoGiaFTQhO6PnAGJO1eMafRr+hSux=6mw () mail ! gmail ! com
[Download RAW message or body]

Hello, boost.

Are the any reasonable cases when construction boost::string_ref from
std::string && is desirable?
I mean that usage string_ref in the following examples is totally wrong,
but not for compiler:

    using std::string;
    using boost::string_ref;

    // 1
    {
        auto ref = string_ref(string("abacaba") + string("upyachka"));
        std::cout << ref << std::endl;
    }
    // 2
    {
        string very_long(1000000, 'a');
        auto ref = string_ref(very_long + "b");
        std::cout << ref << std::endl;
    }

In practice it gets worse, because the first example example works (gcc
4.9.1) thanks to optimizations with short literals, I suspect, and the
second example leads to segmentation fault, as expected.

Those errors can be caught at compile time if class "basic_string_ref"
defintion would contain lines like following:

template<typename Allocator>
basic_string_ref(std::basic_string<charT, traits, Allocator> &&) = delete;

I cannot understant does it prevent any correct usage of string_ref?

-- 
Andrey Davydov

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic