[libcamera-devel] [PATCH] libcamera: revert C++17 specific code for public API

Jean-Michel Hautbois jeanmichel.hautbois at ideasonboard.com
Thu Dec 31 16:47:10 CET 2020


Some applications may not be compliant with C++17 (Chromium, as an
example). Keep the C++17 features for libcamera internals, and C++14
compliance for public API.

This reverts commits 8e42c2feb7ff7c350ffbbf97dd963dfd54e21faa and
6cbdc2859963e17bc897a4022f1d68170477d888.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois at ideasonboard.com>
---
 include/libcamera/bound_method.h |  2 +-
 include/libcamera/controls.h     | 24 +++++------
 include/libcamera/object.h       |  2 +-
 include/libcamera/signal.h       |  4 +-
 include/libcamera/span.h         | 70 +++++++++++++++-----------------
 5 files changed, 48 insertions(+), 54 deletions(-)

diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
index feac51da..95a95653 100644
--- a/include/libcamera/bound_method.h
+++ b/include/libcamera/bound_method.h
@@ -63,7 +63,7 @@ public:
 	}
 	virtual ~BoundMethodBase() = default;
 
-	template<typename T, typename std::enable_if_t<!std::is_same_v<Object, T>> * = nullptr>
+	template<typename T, typename std::enable_if_t<!std::is_same<Object, T>::value> * = nullptr>
 	bool match(T *obj) { return obj == obj_; }
 	bool match(Object *object) { return object == object_; }
 
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 3634dc43..3b7f3347 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -96,9 +96,9 @@ public:
 	ControlValue();
 
 #ifndef __DOXYGEN__
-	template<typename T, typename std::enable_if_t<!details::is_span_v<T> &&
+	template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
 						       details::control_type<T>::value &&
-						       !std::is_same_v<std::string, std::remove_cv_t<T>>,
+						       !std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 	ControlValue(const T &value)
 		: type_(ControlTypeNone), numElements_(0)
@@ -107,8 +107,8 @@ public:
 		    &value, 1, sizeof(T));
 	}
 
-	template<typename T, typename std::enable_if_t<details::is_span_v<T> ||
-						       std::is_same_v<std::string, std::remove_cv_t<T>>,
+	template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
+						       std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 #else
 	template<typename T>
@@ -141,8 +141,8 @@ public:
 	}
 
 #ifndef __DOXYGEN__
-	template<typename T, typename std::enable_if_t<!details::is_span_v<T> &&
-						       !std::is_same_v<std::string, std::remove_cv_t<T>>,
+	template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
+						       !std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 	T get() const
 	{
@@ -152,8 +152,8 @@ public:
 		return *reinterpret_cast<const T *>(data().data());
 	}
 
-	template<typename T, typename std::enable_if_t<details::is_span_v<T> ||
-						       std::is_same_v<std::string, std::remove_cv_t<T>>,
+	template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
+						       std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 #else
 	template<typename T>
@@ -169,8 +169,8 @@ public:
 	}
 
 #ifndef __DOXYGEN__
-	template<typename T, typename std::enable_if_t<!details::is_span_v<T> &&
-						       !std::is_same_v<std::string, std::remove_cv_t<T>>,
+	template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
+						       !std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 	void set(const T &value)
 	{
@@ -178,8 +178,8 @@ public:
 		    reinterpret_cast<const void *>(&value), 1, sizeof(T));
 	}
 
-	template<typename T, typename std::enable_if_t<details::is_span_v<T> ||
-						       std::is_same_v<std::string, std::remove_cv_t<T>>,
+	template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
+						       std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 #else
 	template<typename T>
diff --git a/include/libcamera/object.h b/include/libcamera/object.h
index 423208db..a1882f05 100644
--- a/include/libcamera/object.h
+++ b/include/libcamera/object.h
@@ -32,7 +32,7 @@ public:
 	void postMessage(std::unique_ptr<Message> msg);
 
 	template<typename T, typename R, typename... FuncArgs, typename... Args,
-		 typename std::enable_if_t<std::is_base_of_v<Object, T>> * = nullptr>
+		 typename std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr>
 	R invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type,
 		       Args... args)
 	{
diff --git a/include/libcamera/signal.h b/include/libcamera/signal.h
index 46d917d5..5bcd7a77 100644
--- a/include/libcamera/signal.h
+++ b/include/libcamera/signal.h
@@ -44,7 +44,7 @@ public:
 	}
 
 #ifndef __DOXYGEN__
-	template<typename T, typename R, typename std::enable_if_t<std::is_base_of_v<Object, T>> * = nullptr>
+	template<typename T, typename R, typename std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr>
 	void connect(T *obj, R (T::*func)(Args...),
 		     ConnectionType type = ConnectionTypeAuto)
 	{
@@ -52,7 +52,7 @@ public:
 		SignalBase::connect(new BoundMethodMember<T, void, Args...>(obj, object, func, type));
 	}
 
-	template<typename T, typename R, typename std::enable_if_t<!std::is_base_of_v<Object, T>> * = nullptr>
+	template<typename T, typename R, typename std::enable_if_t<!std::is_base_of<Object, T>::value> * = nullptr>
 #else
 	template<typename T, typename R>
 #endif
diff --git a/include/libcamera/span.h b/include/libcamera/span.h
index e7ffef12..91e9f974 100644
--- a/include/libcamera/span.h
+++ b/include/libcamera/span.h
@@ -31,9 +31,6 @@ template<typename U, std::size_t N>
 struct is_array<std::array<U, N>> : public std::true_type {
 };
 
-template<typename T>
-inline constexpr bool is_array_v = is_array<T>::value;
-
 template<typename U>
 struct is_span : public std::false_type {
 };
@@ -42,9 +39,6 @@ template<typename U, std::size_t Extent>
 struct is_span<Span<U, Extent>> : public std::true_type {
 };
 
-template<typename T>
-inline constexpr bool is_span_v = is_span<T>::value;
-
 } /* namespace details */
 
 namespace utils {
@@ -131,8 +125,8 @@ public:
 
 	template<std::size_t N>
 	constexpr Span(element_type (&arr)[N],
-		       std::enable_if_t<std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
-							      element_type (*)[]> &&
+		       std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
+							    element_type (*)[]>::value &&
 					N == Extent,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(arr)
@@ -141,8 +135,8 @@ public:
 
 	template<std::size_t N>
 	constexpr Span(std::array<value_type, N> &arr,
-		       std::enable_if_t<std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
-							      element_type (*)[]> &&
+		       std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
+							    element_type (*)[]>::value &&
 					N == Extent,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(arr.data())
@@ -151,8 +145,8 @@ public:
 
 	template<std::size_t N>
 	constexpr Span(const std::array<value_type, N> &arr,
-		       std::enable_if_t<std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
-							      element_type (*)[]> &&
+		       std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
+							    element_type (*)[]>::value &&
 					N == Extent,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(arr.data())
@@ -161,11 +155,11 @@ public:
 
 	template<class Container>
 	explicit constexpr Span(Container &cont,
-				std::enable_if_t<!details::is_span_v<Container> &&
-						 !details::is_array_v<Container> &&
-						 !std::is_array_v<Container> &&
-						 std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
-								       element_type (*)[]>,
+				std::enable_if_t<!details::is_span<Container>::value &&
+						 !details::is_array<Container>::value &&
+						 !std::is_array<Container>::value &&
+						 std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
+								     element_type (*)[]>::value,
 						 std::nullptr_t> = nullptr)
 		: data_(utils::data(cont))
 	{
@@ -173,11 +167,11 @@ public:
 
 	template<class Container>
 	explicit constexpr Span(const Container &cont,
-				std::enable_if_t<!details::is_span_v<Container> &&
-						 !details::is_array_v<Container> &&
-						 !std::is_array_v<Container> &&
-						 std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
-								       element_type (*)[]>,
+				std::enable_if_t<!details::is_span<Container>::value &&
+						 !details::is_array<Container>::value &&
+						 !std::is_array<Container>::value &&
+						 std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
+								     element_type (*)[]>::value,
 						 std::nullptr_t> = nullptr)
 		: data_(utils::data(cont))
 	{
@@ -186,7 +180,7 @@ public:
 
 	template<class U, std::size_t N>
 	explicit constexpr Span(const Span<U, N> &s,
-				std::enable_if_t<std::is_convertible_v<U (*)[], element_type (*)[]> &&
+				std::enable_if_t<std::is_convertible<U (*)[], element_type (*)[]>::value &&
 						 N == Extent,
 						 std::nullptr_t> = nullptr) noexcept
 		: data_(s.data())
@@ -299,8 +293,8 @@ public:
 
 	template<std::size_t N>
 	constexpr Span(element_type (&arr)[N],
-		       std::enable_if_t<std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
-							      element_type (*)[]>,
+		       std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
+							    element_type (*)[]>::value,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(arr), size_(N)
 	{
@@ -308,8 +302,8 @@ public:
 
 	template<std::size_t N>
 	constexpr Span(std::array<value_type, N> &arr,
-		       std::enable_if_t<std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
-							      element_type (*)[]>,
+		       std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
+							    element_type (*)[]>::value,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(utils::data(arr)), size_(N)
 	{
@@ -323,11 +317,11 @@ public:
 
 	template<class Container>
 	constexpr Span(Container &cont,
-		       std::enable_if_t<!details::is_span_v<Container> &&
-					!details::is_array_v<Container> &&
-					!std::is_array_v<Container> &&
-					std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
-							      element_type (*)[]>,
+		       std::enable_if_t<!details::is_span<Container>::value &&
+					!details::is_array<Container>::value &&
+					!std::is_array<Container>::value &&
+					std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
+							    element_type (*)[]>::value,
 					std::nullptr_t> = nullptr)
 		: data_(utils::data(cont)), size_(utils::size(cont))
 	{
@@ -335,11 +329,11 @@ public:
 
 	template<class Container>
 	constexpr Span(const Container &cont,
-		       std::enable_if_t<!details::is_span_v<Container> &&
-					!details::is_array_v<Container> &&
-					!std::is_array_v<Container> &&
-					std::is_convertible_v<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
-							      element_type (*)[]>,
+		       std::enable_if_t<!details::is_span<Container>::value &&
+					!details::is_array<Container>::value &&
+					!std::is_array<Container>::value &&
+					std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
+							    element_type (*)[]>::value,
 					std::nullptr_t> = nullptr)
 		: data_(utils::data(cont)), size_(utils::size(cont))
 	{
@@ -347,7 +341,7 @@ public:
 
 	template<class U, std::size_t N>
 	constexpr Span(const Span<U, N> &s,
-		       std::enable_if_t<std::is_convertible_v<U (*)[], element_type (*)[]>,
+		       std::enable_if_t<std::is_convertible<U (*)[], element_type (*)[]>::value,
 					std::nullptr_t> = nullptr) noexcept
 		: data_(s.data()), size_(s.size())
 	{
-- 
2.27.0



More information about the libcamera-devel mailing list