From 4dc04a23cb24ea445408a2f7b78173018e04c0e3 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sat, 23 Mar 2024 19:32:03 -0700 Subject: [PATCH] refactor: Make span default ctr and assignment be `= default` (#4198) Minor simplification. Also add a few `noexcept` in some places that we didn't have them already. --------- Signed-off-by: Larry Gritz --- src/include/OpenImageIO/span.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/include/OpenImageIO/span.h b/src/include/OpenImageIO/span.h index 68719dccb3..8dc7d91751 100644 --- a/src/include/OpenImageIO/span.h +++ b/src/include/OpenImageIO/span.h @@ -89,8 +89,8 @@ class span { using const_reverse_iterator = std::reverse_iterator; static constexpr size_type extent = Extent; - /// Default constructor -- the span points to nothing. - constexpr span () noexcept { } + /// Default constructor -- the span will be `{nullptr,0}`. + constexpr span () noexcept = default; /// Copy constructor (copies the span pointer and length, NOT the data). template @@ -113,7 +113,7 @@ class span { /// Construct from a fixed-length C array. Template magic automatically /// finds the length from the declared type of the array. template - constexpr span (T (&data)[N]) : m_data(data), m_size(N) { } + constexpr span (T (&data)[N]) noexcept : m_data(data), m_size(N) { } /// Construct from std::vector. template @@ -125,29 +125,25 @@ class span { /// `const std::vector` into a `span` (the span isn't const, /// but the data it points to will be). template - span (const std::vector &v) + span (const std::vector &v) noexcept : m_data(v.data()), m_size(v.size()) { } /// Construct from mutable element std::array template - constexpr span (std::array &arr) + constexpr span (std::array &arr) noexcept : m_data(arr.data()), m_size(N) {} /// Construct from read-only element std::array template - constexpr span (const std::array& arr) + constexpr span (const std::array& arr) noexcept : m_data(arr.data()), m_size(N) {} /// Construct a span from an initializer_list. - constexpr span (std::initializer_list il) + constexpr span (std::initializer_list il) noexcept : span (il.begin(), il.size()) { } /// Assignment copies the pointer and length, not the data. - span& operator= (const span ©) { - m_data = copy.data(); - m_size = copy.size(); - return *this; - } + constexpr span& operator= (const span ©) = default; /// Subview containing the first Count elements of the span. template