@@ -66,6 +66,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;
@@ -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)