Don't construct string_view|string_ref from rvalue string. That way lies pain

This commit is contained in:
Marshall Clow 2017-02-13 08:15:44 -08:00
parent ccfd741c0a
commit 9960d9f395
2 changed files with 14 additions and 0 deletions

View File

@ -92,6 +92,13 @@ namespace boost {
basic_string_ref(const std::basic_string<charT, traits, Allocator>& str) basic_string_ref(const std::basic_string<charT, traits, Allocator>& str)
: ptr_(str.data()), len_(str.length()) {} : ptr_(str.data()), len_(str.length()) {}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
// Constructing a string_ref from a temporary string is a bad idea
template<typename Allocator>
basic_string_ref(std::basic_string<charT, traits, Allocator>&& str)
= delete;
#endif
BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT
: ptr_(str), len_(len) {} : ptr_(str), len_(len) {}

View File

@ -95,6 +95,13 @@ namespace boost {
Allocator>& str) BOOST_NOEXCEPT Allocator>& str) BOOST_NOEXCEPT
: ptr_(str.data()), len_(str.length()) {} : ptr_(str.data()), len_(str.length()) {}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
// Constructing a string_view from a temporary string is a bad idea
template<typename Allocator>
basic_string_view(std::basic_string<charT, traits, Allocator>&& str)
= delete;
#endif
BOOST_CONSTEXPR basic_string_view(const charT* str) BOOST_CONSTEXPR basic_string_view(const charT* str)
: ptr_(str), len_(traits::length(str)) {} : ptr_(str), len_(traits::length(str)) {}