utility: type_traits: use C++14 '_t' style
Add a foo_t variant of all type templates and refactor
usages to use the foo_t variant instead of `foo<...>::type`.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I67a597d5c0ced331398a5f4267504299bc351682
diff --git a/include/sdbusplus/asio/connection.hpp b/include/sdbusplus/asio/connection.hpp
index 6f01596..61c2583 100644
--- a/include/sdbusplus/asio/connection.hpp
+++ b/include/sdbusplus/asio/connection.hpp
@@ -130,8 +130,7 @@
const InputArgs&... a)
{
using FunctionTuple = boost::callable_traits::args_t<MessageHandler>;
- using FunctionTupleType =
- typename utility::decay_tuple<FunctionTuple>::type;
+ using FunctionTupleType = utility::decay_tuple_t<FunctionTuple>;
constexpr bool returnWithMsg = []() {
if constexpr ((std::tuple_size_v<FunctionTupleType>) > 1)
{
@@ -141,9 +140,8 @@
}
return false;
}();
- using UnpackType =
- typename utility::strip_first_n_args<returnWithMsg ? 2 : 1,
- FunctionTupleType>::type;
+ using UnpackType = utility::strip_first_n_args_t<returnWithMsg ? 2 : 1,
+ FunctionTupleType>;
auto applyHandler = [handler = std::forward<MessageHandler>(handler)](
boost::system::error_code ec,
message::message& r) mutable {
@@ -270,7 +268,7 @@
}
else if constexpr (sizeof...(RetTypes) == 1)
{
- if constexpr (std::is_same<utility::first_type<RetTypes...>,
+ if constexpr (std::is_same<utility::first_type_t<RetTypes...>,
void>::value)
{
return;
@@ -278,7 +276,7 @@
else
{
// single item return
- utility::first_type<RetTypes...> responseData{};
+ utility::first_type_t<RetTypes...> responseData{};
// before attempting to read, check ec and bail on error
if (ec)
{
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index 4fd04c7..1046272 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -53,21 +53,20 @@
template <typename T>
using FirstArgIsYield =
- std::is_same<typename utility::get_first_arg<typename utility::decay_tuple<
- boost::callable_traits::args_t<T>>::type>::type,
+ std::is_same<utility::get_first_arg_t<
+ utility::decay_tuple_t<boost::callable_traits::args_t<T>>>,
boost::asio::yield_context>;
template <typename T>
using FirstArgIsMessage =
- std::is_same<typename utility::get_first_arg<typename utility::decay_tuple<
- boost::callable_traits::args_t<T>>::type>::type,
+ std::is_same<utility::get_first_arg_t<
+ utility::decay_tuple_t<boost::callable_traits::args_t<T>>>,
message::message>;
template <typename T>
using SecondArgIsMessage = std::is_same<
- typename utility::get_first_arg<
- typename utility::strip_first_arg<typename utility::decay_tuple<
- boost::callable_traits::args_t<T>>::type>::type>::type,
+ utility::get_first_arg_t<utility::strip_first_arg_t<
+ utility::decay_tuple_t<boost::callable_traits::args_t<T>>>>,
message::message>;
template <typename T>
static constexpr bool callbackYields = FirstArgIsYield<T>::value;
@@ -124,8 +123,7 @@
private:
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
- using InputTupleType =
- typename utility::decay_tuple<CallbackSignature>::type;
+ using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
using ResultType = boost::callable_traits::return_type_t<CallbackType>;
CallbackType func_;
template <typename T>
@@ -145,9 +143,8 @@
// optional message-first-argument callback
int expandCall(message::message& m)
{
- using DbusTupleType = typename utility::strip_first_n_args<
- details::NonDbusArgsCount<InputTupleType>::size(),
- InputTupleType>::type;
+ using DbusTupleType = utility::strip_first_n_args_t<
+ details::NonDbusArgsCount<InputTupleType>::size(), InputTupleType>;
DbusTupleType dbusArgs;
if (!utility::read_into_tuple(dbusArgs, m))
@@ -231,8 +228,7 @@
private:
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
- using InputTupleType =
- typename utility::decay_tuple<CallbackSignature>::type;
+ using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
using ResultType = boost::callable_traits::return_type_t<CallbackType>;
boost::asio::io_context& io_;
CallbackType func_;
@@ -252,9 +248,8 @@
// co-routine body for call
void expandCall(boost::asio::yield_context yield, message::message& m)
{
- using DbusTupleType = typename utility::strip_first_n_args<
- details::NonDbusArgsCount<InputTupleType>::size(),
- InputTupleType>::type;
+ using DbusTupleType = utility::strip_first_n_args_t<
+ details::NonDbusArgsCount<InputTupleType>::size(), InputTupleType>;
DbusTupleType dbusArgs;
try
{
@@ -559,11 +554,10 @@
bool register_method(const std::string& name, CallbackType&& handler)
{
using ActualSignature = boost::callable_traits::args_t<CallbackType>;
- using CallbackSignature = typename utility::strip_first_n_args<
+ using CallbackSignature = utility::strip_first_n_args_t<
details::NonDbusArgsCount<ActualSignature>::size(),
- ActualSignature>::type;
- using InputTupleType =
- typename utility::decay_tuple<CallbackSignature>::type;
+ ActualSignature>;
+ using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
using ResultType = boost::callable_traits::return_type_t<CallbackType>;
if (initialized_)
@@ -601,8 +595,7 @@
bool register_method(const std::string& name, CallbackType&& handler)
{
using CallbackSignature = boost::callable_traits::args_t<CallbackType>;
- using InputTupleType =
- typename utility::decay_tuple<CallbackSignature>::type;
+ using InputTupleType = utility::decay_tuple_t<CallbackSignature>;
using ResultType = boost::callable_traits::return_type_t<CallbackType>;
if (initialized_)
diff --git a/include/sdbusplus/utility/type_traits.hpp b/include/sdbusplus/utility/type_traits.hpp
index 51f5081..2031de4 100644
--- a/include/sdbusplus/utility/type_traits.hpp
+++ b/include/sdbusplus/utility/type_traits.hpp
@@ -14,7 +14,7 @@
* @tparam Types - the parameter pack
*/
template <typename... Types>
-using first_type = std::tuple_element_t<0, std::tuple<Types...>>;
+using first_type_t = std::tuple_element_t<0, std::tuple<Types...>>;
/** @brief Convert T[N] to T* if is_same<Tbase,T>
*
@@ -47,11 +47,17 @@
using type = std::tuple<>;
};
+template <std::size_t N, typename... Args>
+using strip_first_n_args_t = typename strip_first_n_args<N, Args...>::type;
+
// Small helper class for stripping off the error code from the function
// argument definitions so unpack can be called appropriately
template <typename T>
using strip_first_arg = strip_first_n_args<1, T>;
+template <typename T>
+using strip_first_arg_t = typename strip_first_arg<T>::type;
+
// matching helper class to only return the first type
template <typename T>
struct get_first_arg
@@ -65,6 +71,9 @@
using type = FirstArg;
};
+template <typename... Args>
+using get_first_arg_t = typename get_first_arg<Args...>::type;
+
// helper class to remove const and reference from types
template <typename T>
struct decay_tuple
@@ -76,6 +85,9 @@
using type = std::tuple<typename std::decay<Args>::type...>;
};
+template <typename... Args>
+using decay_tuple_t = typename decay_tuple<Args...>::type;
+
// Small helper class for stripping off the first + last character of a char
// array
template <std::size_t N, std::size_t... Is>