From c56dd13592daa332a74b90aeca8724c5b3cc3d5d Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 27 Jul 2016 11:18:18 -0700 Subject: [PATCH] Mark the copy ctor/assignment operator as '= default' when the compiler supports it. This makes these types trivially copy/move assignable/constructible. See https://svn.boost.org/trac/boost/ticket/11684 --- include/boost/utility/string_ref.hpp | 21 ++++++++++++++++----- include/boost/utility/string_view.hpp | 13 ++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/boost/utility/string_ref.hpp b/include/boost/utility/string_ref.hpp index 8707157..1283f38 100644 --- a/include/boost/utility/string_ref.hpp +++ b/include/boost/utility/string_ref.hpp @@ -57,26 +57,37 @@ namespace boost { static BOOST_CONSTEXPR_OR_CONST size_type npos = size_type(-1); // construct/copy - BOOST_CONSTEXPR basic_string_ref () + BOOST_CONSTEXPR basic_string_ref () BOOST_NOEXCEPT : ptr_(NULL), len_(0) {} - BOOST_CONSTEXPR basic_string_ref (const basic_string_ref &rhs) + // by defaulting these functions, basic_string_ref becomes + // trivially copy/move constructible. + BOOST_CONSTEXPR basic_string_ref (const basic_string_ref &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else : ptr_(rhs.ptr_), len_(rhs.len_) {} +#endif - basic_string_ref& operator=(const basic_string_ref &rhs) { + basic_string_ref& operator=(const basic_string_ref &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else + { ptr_ = rhs.ptr_; len_ = rhs.len_; return *this; } +#endif - basic_string_ref(const charT* str) + basic_string_ref(const charT* str) BOOST_NOEXCEPT : ptr_(str), len_(traits::length(str)) {} template basic_string_ref(const std::basic_string& str) : ptr_(str.data()), len_(str.length()) {} - BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) + BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT : ptr_(str), len_(len) {} #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 9de32cc..070927d 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -65,14 +65,25 @@ namespace boost { BOOST_CONSTEXPR basic_string_view() BOOST_NOEXCEPT : ptr_(NULL), len_(0) {} + // by defaulting these functions, basic_string_ref becomes + // trivially copy/move constructible. BOOST_CONSTEXPR basic_string_view(const basic_string_view &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else : ptr_(rhs.ptr_), len_(rhs.len_) {} +#endif - basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT { + basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT +#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + = default; +#else + { ptr_ = rhs.ptr_; len_ = rhs.len_; return *this; } +#endif template basic_string_view(const std::basic_string