use C++17 std::foo_v templates
Use the C++17 style `foo_v` template aliases rather than
the older `foo<...>::value` style.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I8510f94ead11142a71d5b1e17c64fdd53a74d741
diff --git a/include/sdbusplus/asio/connection.hpp b/include/sdbusplus/asio/connection.hpp
index 61c2583..7787b61 100644
--- a/include/sdbusplus/asio/connection.hpp
+++ b/include/sdbusplus/asio/connection.hpp
@@ -268,8 +268,8 @@
}
else if constexpr (sizeof...(RetTypes) == 1)
{
- if constexpr (std::is_same<utility::first_type_t<RetTypes...>,
- void>::value)
+ if constexpr (std::is_same_v<utility::first_type_t<RetTypes...>,
+ void>)
{
return;
}
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index 1046272..dfdf1e3 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -52,27 +52,27 @@
};
template <typename T>
-using FirstArgIsYield =
- std::is_same<utility::get_first_arg_t<
- utility::decay_tuple_t<boost::callable_traits::args_t<T>>>,
- boost::asio::yield_context>;
+inline const bool FirstArgIsYield_v =
+ std::is_same_v<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<utility::get_first_arg_t<
- utility::decay_tuple_t<boost::callable_traits::args_t<T>>>,
- message::message>;
+inline const bool FirstArgIsMessage_v =
+ std::is_same_v<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<
+inline const bool SecondArgIsMessage_v = std::is_same_v<
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;
+static constexpr bool callbackYields = FirstArgIsYield_v<T>;
template <typename T>
-static constexpr bool callbackWantsMessage = (FirstArgIsMessage<T>::value ||
- SecondArgIsMessage<T>::value);
+static constexpr bool callbackWantsMessage = (FirstArgIsMessage_v<T> ||
+ SecondArgIsMessage_v<T>);
#ifdef __cpp_if_constexpr
namespace details
@@ -96,8 +96,8 @@
{
constexpr static std::size_t size()
{
- if constexpr (std::is_same<FirstArg, message::message>::value ||
- std::is_same<FirstArg, boost::asio::yield_context>::value)
+ if constexpr (std::is_same_v<FirstArg, message::message> ||
+ std::is_same_v<FirstArg, boost::asio::yield_context>)
{
return 1 + NonDbusArgsCount<std::tuple<OtherArgs...>>::size();
}
@@ -127,14 +127,14 @@
using ResultType = boost::callable_traits::return_type_t<CallbackType>;
CallbackType func_;
template <typename T>
- std::enable_if_t<!std::is_void<T>::value, void>
+ std::enable_if_t<!std::is_void_v<T>, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
- std::enable_if_t<std::is_void<T>::value, void>
+ std::enable_if_t<std::is_void_v<T>, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
std::apply(func_, inputArgs);
@@ -233,14 +233,14 @@
boost::asio::io_context& io_;
CallbackType func_;
template <typename T>
- std::enable_if_t<!std::is_void<T>::value, void>
+ std::enable_if_t<!std::is_void_v<T>, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
ResultType r = std::apply(func_, inputArgs);
m.append(r);
}
template <typename T>
- std::enable_if_t<std::is_void<T>::value, void>
+ std::enable_if_t<std::is_void_v<T>, void>
callFunction(message::message& m, InputTupleType& inputArgs)
{
std::apply(func_, inputArgs);
diff --git a/include/sdbusplus/message/append.hpp b/include/sdbusplus/message/append.hpp
index 284146d..9e9827b 100644
--- a/include/sdbusplus/message/append.hpp
+++ b/include/sdbusplus/message/append.hpp
@@ -162,8 +162,8 @@
{
// For this default implementation, we need to ensure that only
// basic types are used.
- static_assert(std::is_fundamental<Td<T>>::value ||
- std::is_convertible<Td<T>, const char*>::value,
+ static_assert(std::is_fundamental_v<Td<T>> ||
+ std::is_convertible_v<Td<T>, const char*>,
"Non-basic types are not allowed.");
constexpr auto dbusType = std::get<0>(types::type_id<T>());
@@ -383,15 +383,11 @@
* sd_bus_message_append.
*/
template <typename Tuple>
-std::enable_if_t<2 <= std::tuple_size<Tuple>::value>
+std::enable_if_t<2 <= std::tuple_size_v<Tuple>>
append_tuple(sdbusplus::SdBusInterface* intf, sd_bus_message* m, Tuple&& t)
{
// This was called because the tuple had at least 2 items in it.
-
- AppendHelper<std::tuple_size<Tuple>::value>::op(intf, m, std::move(t));
-
- // append_tuple(intf, m, std::move(t),
- // std::make_index_sequence<std::tuple_size<Tuple>::value>());
+ AppendHelper<std::tuple_size_v<Tuple>>::op(intf, m, std::move(t));
}
/** @brief Append a tuple of exactly 1 entry into the sd_bus_message.
@@ -405,7 +401,7 @@
* can_append_multiple::value == false.
*/
template <typename Tuple>
-std::enable_if_t<1 == std::tuple_size<Tuple>::value>
+std::enable_if_t<1 == std::tuple_size_v<Tuple>>
append_tuple(sdbusplus::SdBusInterface* intf, sd_bus_message* m, Tuple&& t)
{
using itemType = decltype(std::get<0>(t));
@@ -418,7 +414,7 @@
* This a no-op function that is useful due to variadic templates.
*/
template <typename Tuple>
-std::enable_if_t<0 == std::tuple_size<Tuple>::value> inline append_tuple(
+std::enable_if_t<0 == std::tuple_size_v<Tuple>> inline append_tuple(
sdbusplus::SdBusInterface* /*intf*/, sd_bus_message* /*m*/, Tuple&& /*t*/)
{}
diff --git a/include/sdbusplus/message/read.hpp b/include/sdbusplus/message/read.hpp
index f13d3ae..46721f8 100644
--- a/include/sdbusplus/message/read.hpp
+++ b/include/sdbusplus/message/read.hpp
@@ -144,8 +144,8 @@
{
// For this default implementation, we need to ensure that only
// basic types are used.
- static_assert(std::is_fundamental<Td<T>>::value ||
- std::is_convertible<Td<T>, const char*>::value,
+ static_assert(std::is_fundamental_v<Td<T>> ||
+ std::is_convertible_v<Td<T>, const char*>,
"Non-basic types are not allowed.");
constexpr auto dbusType = std::get<0>(types::type_id<T>());
@@ -486,12 +486,10 @@
* sd_bus_message_read.
*/
template <typename Tuple>
-std::enable_if_t<2 <= std::tuple_size<Tuple>::value>
+std::enable_if_t<2 <= std::tuple_size_v<Tuple>>
read_tuple(sdbusplus::SdBusInterface* intf, sd_bus_message* m, Tuple&& t)
{
- ReadHelper<std::tuple_size<Tuple>::value>::op(intf, m, std::move(t));
- // read_tuple(intf, m, std::move(t),
- // std::make_index_sequence<std::tuple_size<Tuple>::value>());
+ ReadHelper<std::tuple_size_v<Tuple>>::op(intf, m, std::move(t));
}
/** @brief Read a tuple of exactly 1 entry from the sd_bus_message.
@@ -505,7 +503,7 @@
* can_read_multiple::value == false.
*/
template <typename Tuple>
-std::enable_if_t<1 == std::tuple_size<Tuple>::value>
+std::enable_if_t<1 == std::tuple_size_v<Tuple>>
read_tuple(sdbusplus::SdBusInterface* intf, sd_bus_message* m, Tuple&& t)
{
using itemType = decltype(std::get<0>(t));
@@ -518,7 +516,7 @@
* This a no-op function that is useful due to variadic templates.
*/
template <typename Tuple>
-std::enable_if_t<0 == std::tuple_size<Tuple>::value> inline read_tuple(
+std::enable_if_t<0 == std::tuple_size_v<Tuple>> inline read_tuple(
sdbusplus::SdBusInterface* /*intf*/, sd_bus_message* /*m*/, Tuple&& /*t*/)
{}
diff --git a/include/sdbusplus/message/types.hpp b/include/sdbusplus/message/types.hpp
index 6aaafd9..1adc9b4 100644
--- a/include/sdbusplus/message/types.hpp
+++ b/include/sdbusplus/message/types.hpp
@@ -268,7 +268,7 @@
template <typename T>
constexpr auto type_id_single()
{
- static_assert(!std::is_base_of<undefined_type_id, type_id<T>>::value,
+ static_assert(!std::is_base_of_v<undefined_type_id, type_id<T>>,
"No dbus type conversion provided for type.");
return type_id<T>::value;
}
diff --git a/include/sdbusplus/utility/container_traits.hpp b/include/sdbusplus/utility/container_traits.hpp
index 92b9dba..eb5d625 100644
--- a/include/sdbusplus/utility/container_traits.hpp
+++ b/include/sdbusplus/utility/container_traits.hpp
@@ -52,7 +52,7 @@
public:
static constexpr bool value =
- std::is_same<std::true_type, decltype(test<T, dummy>(nullptr))>::value;
+ std::is_same_v<std::true_type, decltype(test<T, dummy>(nullptr))>;
};
/** has_emplace_method - Determine if type has a method template named
@@ -78,7 +78,7 @@
public:
static constexpr bool value =
- std::is_same<std::true_type, decltype(test<T, dummy>(nullptr))>::value;
+ std::is_same_v<std::true_type, decltype(test<T, dummy>(nullptr))>;
};
} // namespace utility
diff --git a/include/sdbusplus/utility/type_traits.hpp b/include/sdbusplus/utility/type_traits.hpp
index 2031de4..2b0ddd0 100644
--- a/include/sdbusplus/utility/type_traits.hpp
+++ b/include/sdbusplus/utility/type_traits.hpp
@@ -23,8 +23,8 @@
*/
template <typename Tbase, typename T>
using array_to_ptr_t = typename std::conditional_t<
- std::is_array<T>::value,
- std::conditional_t<std::is_same<Tbase, std::remove_extent_t<T>>::value,
+ std::is_array_v<T>,
+ std::conditional_t<std::is_same_v<Tbase, std::remove_extent_t<T>>,
std::add_pointer_t<std::remove_extent_t<T>>, T>,
T>;
diff --git a/test/utility/type_traits.cpp b/test/utility/type_traits.cpp
index 81fa076..a192bdf 100644
--- a/test/utility/type_traits.cpp
+++ b/test/utility/type_traits.cpp
@@ -9,21 +9,21 @@
{
using sdbusplus::utility::array_to_ptr_t;
-using std::is_same;
+using std::is_same_v;
TEST(TypeTraits, Basic)
{
- static_assert(is_same<char, array_to_ptr_t<char, char>>::value,
+ static_assert(is_same_v<char, array_to_ptr_t<char, char>>,
"array_to_ptr_t<char, char> != char");
- static_assert(is_same<char*, array_to_ptr_t<char, char*>>::value,
+ static_assert(is_same_v<char*, array_to_ptr_t<char, char*>>,
"array_to_ptr_t<char, char*> != char*");
- static_assert(is_same<char*, array_to_ptr_t<char, char[100]>>::value,
+ static_assert(is_same_v<char*, array_to_ptr_t<char, char[100]>>,
"array_to_ptr_t<char, char[100]> != char*");
- static_assert(is_same<char[100], array_to_ptr_t<int, char[100]>>::value,
+ static_assert(is_same_v<char[100], array_to_ptr_t<int, char[100]>>,
"array_to_ptr_t<int, char[100]> != char[100]");
}