[libcamera-devel] [PATCH] libcamera: Use C++14 std::*_t type traits

Niklas Söderlund niklas.soderlund at ragnatech.se
Mon Feb 17 13:20:05 CET 2020


Hi Laurent,

Thanks for your work.

On 2020-02-16 02:13:04 +0200, Laurent Pinchart wrote:
> C++14 introduced useful type traits helpers named std::*_t as aliases to
> std::*<...>::type. Use them to simplify the code.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  include/libcamera/bound_method.h |  6 +++---
>  include/libcamera/object.h       |  2 +-
>  include/libcamera/signal.h       |  4 ++--
>  src/libcamera/ipa_module.cpp     | 10 +++++-----
>  4 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h
> index 7ffd2e426e18..983bb5cbbad0 100644
> --- a/include/libcamera/bound_method.h
> +++ b/include/libcamera/bound_method.h
> @@ -38,7 +38,7 @@ public:
>  	{
>  	}
>  
> -	std::tuple<typename std::remove_reference<Args>::type...> args_;
> +	std::tuple<typename std::remove_reference_t<Args>...> args_;
>  	R ret_;
>  };
>  
> @@ -51,7 +51,7 @@ public:
>  	{
>  	}
>  
> -	std::tuple<typename std::remove_reference<Args>::type...> args_;
> +	std::tuple<typename std::remove_reference_t<Args>...> args_;
>  };
>  
>  class BoundMethodBase
> @@ -63,7 +63,7 @@ public:
>  	}
>  	virtual ~BoundMethodBase() {}
>  
> -	template<typename T, typename std::enable_if<!std::is_same<Object, T>::value>::type * = 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/object.h b/include/libcamera/object.h
> index 4d16f3f2b610..9a3dd0702d39 100644
> --- a/include/libcamera/object.h
> +++ b/include/libcamera/object.h
> @@ -30,7 +30,7 @@ public:
>  	void postMessage(std::unique_ptr<Message> msg);
>  
>  	template<typename T, typename R, typename... FuncArgs, typename... Args,
> -		 typename std::enable_if<std::is_base_of<Object, T>::value>::type * = 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 c13bb30f0636..ed30eb559127 100644
> --- a/include/libcamera/signal.h
> +++ b/include/libcamera/signal.h
> @@ -45,7 +45,7 @@ public:
>  	}
>  
>  #ifndef __DOXYGEN__
> -	template<typename T, typename R, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = 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)
>  	{
> @@ -53,7 +53,7 @@ public:
>  		SignalBase::connect(new BoundMethodMember<T, void, Args...>(obj, object, func, type));
>  	}
>  
> -	template<typename T, typename R, typename std::enable_if<!std::is_base_of<Object, T>::value>::type * = 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/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index de65525b8319..a01d0757ff8f 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -42,20 +42,20 @@ LOG_DEFINE_CATEGORY(IPAModule)
>  namespace {
>  
>  template<typename T>
> -typename std::remove_extent<T>::type *elfPointer(void *map, off_t offset,
> -						 size_t fileSize, size_t objSize)
> +typename std::remove_extent_t<T> *elfPointer(void *map, off_t offset,
> +					     size_t fileSize, size_t objSize)
>  {
>  	size_t size = offset + objSize;
>  	if (size > fileSize || size < objSize)
>  		return nullptr;
>  
> -	return reinterpret_cast<typename std::remove_extent<T>::type *>
> +	return reinterpret_cast<typename std::remove_extent_t<T> *>
>  		(static_cast<char *>(map) + offset);
>  }
>  
>  template<typename T>
> -typename std::remove_extent<T>::type *elfPointer(void *map, off_t offset,
> -						 size_t fileSize)
> +typename std::remove_extent_t<T> *elfPointer(void *map, off_t offset,
> +					     size_t fileSize)
>  {
>  	return elfPointer<T>(map, offset, fileSize, sizeof(T));
>  }
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list