From 0a4d996a252bdb4e83cf322e0efff8f4a51a5ba0 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sat, 23 Mar 2024 10:38:54 -0700 Subject: [PATCH 1/2] refactor: Make span default ctr and assignment be `= default` Signed-off-by: Larry Gritz --- src/include/OpenImageIO/span.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/include/OpenImageIO/span.h b/src/include/OpenImageIO/span.h index 68719dccb3..69adb039b9 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 @@ -143,11 +143,7 @@ class span { : 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 From 1c026d548ea7daa56da9309295e32adb16faab46 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sat, 23 Mar 2024 15:28:58 -0700 Subject: [PATCH 2/2] Mark several additional span methods as noexcept Signed-off-by: Larry Gritz --- src/include/OpenImageIO/span.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/include/OpenImageIO/span.h b/src/include/OpenImageIO/span.h index 69adb039b9..8dc7d91751 100644 --- a/src/include/OpenImageIO/span.h +++ b/src/include/OpenImageIO/span.h @@ -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,21 +125,21 @@ 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.