diff --git a/include/boost/utility/string_ref.hpp b/include/boost/utility/string_ref.hpp index 5acf346..ea47f76 100644 --- a/include/boost/utility/string_ref.hpp +++ b/include/boost/utility/string_ref.hpp @@ -92,6 +92,13 @@ namespace boost { basic_string_ref(const std::basic_string& str) : 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 + basic_string_ref(std::basic_string&& str) + = delete; +#endif + BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT : ptr_(str), len_(len) {} diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 410bd88..935dcb6 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -95,6 +95,13 @@ namespace boost { Allocator>& str) BOOST_NOEXCEPT : 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 + basic_string_view(std::basic_string&& str) + = delete; +#endif + BOOST_CONSTEXPR basic_string_view(const charT* str) : ptr_(str), len_(traits::length(str)) {}