Message ID | 20200110193808.2266294-4-niklas.soderlund@ragnatech.se |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Niklas, Thank you for the patch. On Fri, Jan 10, 2020 at 08:37:38PM +0100, Niklas Söderlund wrote: > C++11 does not support std::exchange(), add a custom implementation in > utils. This is now only used by the FrameBuffer move constructor, which I think should be dropped (I'll comment on that in the corresponding patch), so this patch could possibly be dropped too. > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/libcamera/include/utils.h | 9 +++++++++ > src/libcamera/utils.cpp | 8 ++++++++ > 2 files changed, 17 insertions(+) > > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h > index badc77533fa15f09..6470cadc2c6c1234 100644 > --- a/src/libcamera/include/utils.h > +++ b/src/libcamera/include/utils.h > @@ -67,6 +67,15 @@ const T& clamp(const T& v, const T& lo, const T& hi) > return std::max(lo, std::min(v, hi)); > } > > +/* C++11 doesn't provide std::exchange */ > +template<class T, class U = T> > +T exchange(T &obj, U &&new_value) > +{ > + T old_value = std::move(obj); > + obj = std::forward<U>(new_value); > + return old_value; > +} > + > using clock = std::chrono::steady_clock; > using duration = std::chrono::steady_clock::duration; > using time_point = std::chrono::steady_clock::time_point; > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp > index 5de9e4813353b23c..a7e573ac45aec914 100644 > --- a/src/libcamera/utils.cpp > +++ b/src/libcamera/utils.cpp > @@ -95,6 +95,14 @@ char *secure_getenv(const char *name) > * \return lo if v is less than lo, hi if v is greater than hi, otherwise v > */ > > +/** > + * \fn libcamera::utils::exchange(T &obj, U &&new_value) > + * \brief Replace the value of \a obj with \a new_value and return the old value > + * \param[inout] obj Object whose value to replace > + * \param[in] new_value The value to assign to obj > + * \return The old value of \a obj > + */ > + > /** > * \typedef clock > * \brief The libcamera clock (monotonic)
diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index badc77533fa15f09..6470cadc2c6c1234 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -67,6 +67,15 @@ const T& clamp(const T& v, const T& lo, const T& hi) return std::max(lo, std::min(v, hi)); } +/* C++11 doesn't provide std::exchange */ +template<class T, class U = T> +T exchange(T &obj, U &&new_value) +{ + T old_value = std::move(obj); + obj = std::forward<U>(new_value); + return old_value; +} + using clock = std::chrono::steady_clock; using duration = std::chrono::steady_clock::duration; using time_point = std::chrono::steady_clock::time_point; diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 5de9e4813353b23c..a7e573ac45aec914 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -95,6 +95,14 @@ char *secure_getenv(const char *name) * \return lo if v is less than lo, hi if v is greater than hi, otherwise v */ +/** + * \fn libcamera::utils::exchange(T &obj, U &&new_value) + * \brief Replace the value of \a obj with \a new_value and return the old value + * \param[inout] obj Object whose value to replace + * \param[in] new_value The value to assign to obj + * \return The old value of \a obj + */ + /** * \typedef clock * \brief The libcamera clock (monotonic)