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