From 72e29d32e1f68bcf02a1d2682de9781eaac84db1 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Sun, 17 Dec 2023 21:23:05 +0100 Subject: [PATCH] std::tuple_size{} to std::tuple_size_v whereever applicable --- include/rfl/NamedTuple.hpp | 8 ++-- include/rfl/internal/find_index.hpp | 2 +- .../rfl/internal/nt_to_ptr_named_tuple.hpp | 47 +++++++++---------- include/rfl/internal/remove_fields.hpp | 46 +++++++++--------- include/rfl/internal/tup_to_ptr_tuple.hpp | 2 +- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/include/rfl/NamedTuple.hpp b/include/rfl/NamedTuple.hpp index e402992d..796bc02d 100644 --- a/include/rfl/NamedTuple.hpp +++ b/include/rfl/NamedTuple.hpp @@ -320,7 +320,7 @@ class NamedTuple { template auto make_fields(Args&&... _args) { constexpr auto size = sizeof...(Args) - num_additional_fields; - constexpr auto num_fields = std::tuple_size{}; + constexpr auto num_fields = std::tuple_size_v; constexpr auto i = num_fields - size - 1; constexpr bool retrieved_all_fields = size == num_fields; @@ -342,7 +342,7 @@ class NamedTuple { template auto make_fields(Args&&... _args) const { constexpr auto size = sizeof...(Args) - num_additional_fields; - constexpr auto num_fields = std::tuple_size{}; + constexpr auto num_fields = std::tuple_size_v; constexpr auto i = num_fields - size - 1; constexpr bool retrieved_all_fields = size == num_fields; @@ -363,7 +363,7 @@ class NamedTuple { auto make_replaced(V&& _values, T&& _val, Args&&... _args) const { constexpr auto size = sizeof...(Args); - constexpr bool retrieved_all_fields = size == std::tuple_size{}; + constexpr bool retrieved_all_fields = size == std::tuple_size_v; if constexpr (retrieved_all_fields) { return NamedTuple(std::forward(_args)...); @@ -434,7 +434,7 @@ class NamedTuple { std::tuple&& _other_fields, Args&&... _args) { constexpr auto size = sizeof...(Args); - constexpr bool retrieved_all_fields = size == std::tuple_size{}; + constexpr bool retrieved_all_fields = size == std::tuple_size_v; if constexpr (retrieved_all_fields) { return std::make_tuple(std::forward(_args)...); diff --git a/include/rfl/internal/find_index.hpp b/include/rfl/internal/find_index.hpp index f4cb628f..940ea8fd 100644 --- a/include/rfl/internal/find_index.hpp +++ b/include/rfl/internal/find_index.hpp @@ -19,7 +19,7 @@ constexpr static int find_index() { if constexpr (name_i_matches) { return I; } else { - constexpr bool out_of_range = I + 1 == std::tuple_size{}; + constexpr bool out_of_range = I + 1 == std::tuple_size_v; static_assert(!out_of_range, "Field name not found!"); diff --git a/include/rfl/internal/nt_to_ptr_named_tuple.hpp b/include/rfl/internal/nt_to_ptr_named_tuple.hpp index b8215aa1..6e6278c5 100644 --- a/include/rfl/internal/nt_to_ptr_named_tuple.hpp +++ b/include/rfl/internal/nt_to_ptr_named_tuple.hpp @@ -13,40 +13,39 @@ namespace internal { /// the struct from a named tuple. template auto nt_to_ptr_named_tuple(NamedTupleType& _nt, AlreadyExtracted... _a) { - using Fields = typename NamedTupleType::Fields; + using Fields = typename NamedTupleType::Fields; - constexpr auto i = sizeof...(AlreadyExtracted); - constexpr auto num_fields = std::tuple_size{}; + constexpr auto i = sizeof...(AlreadyExtracted); + constexpr auto num_fields = std::tuple_size_v; - if constexpr (i == num_fields) { - return make_named_tuple(_a...); - } else { - using FieldType = typename std::tuple_element::type; - using T = std::decay_t; - return nt_to_ptr_named_tuple( - _nt, _a..., - Field(&std::get(_nt.values()))); - } + if constexpr (i == num_fields) { + return make_named_tuple(_a...); + } else { + using FieldType = typename std::tuple_element::type; + using T = std::decay_t; + return nt_to_ptr_named_tuple( + _nt, _a..., Field(&std::get(_nt.values()))); + } } /// Generates a named tuple that contains pointers to the original values in /// the struct from a named tuple. template auto nt_to_ptr_named_tuple(const NamedTupleType& _nt, AlreadyExtracted... _a) { - using Fields = typename NamedTupleType::Fields; + using Fields = typename NamedTupleType::Fields; - constexpr auto i = sizeof...(AlreadyExtracted); - constexpr auto num_fields = std::tuple_size{}; + constexpr auto i = sizeof...(AlreadyExtracted); + constexpr auto num_fields = std::tuple_size_v; - if constexpr (i == num_fields) { - return make_named_tuple(_a...); - } else { - using FieldType = typename std::tuple_element::type; - using T = std::decay_t; - return nt_to_ptr_named_tuple( - _nt, _a..., - Field(&std::get(_nt.values()))); - } + if constexpr (i == num_fields) { + return make_named_tuple(_a...); + } else { + using FieldType = typename std::tuple_element::type; + using T = std::decay_t; + return nt_to_ptr_named_tuple( + _nt, _a..., + Field(&std::get(_nt.values()))); + } } } // namespace internal diff --git a/include/rfl/internal/remove_fields.hpp b/include/rfl/internal/remove_fields.hpp index 5aab4c6f..bc26dfbd 100644 --- a/include/rfl/internal/remove_fields.hpp +++ b/include/rfl/internal/remove_fields.hpp @@ -22,27 +22,27 @@ struct remove_single_field; template struct remove_single_field<_OldNamedTupleType, _name, _NewNamedTupleType, 0> { - using type = _NewNamedTupleType; + using type = _NewNamedTupleType; }; /// General case. template struct remove_single_field { - using OldNamedTupleType = std::decay_t<_OldNamedTupleType>; + using OldNamedTupleType = std::decay_t<_OldNamedTupleType>; - constexpr static int num_fields = - std::tuple_size{}; + constexpr static int num_fields = + std::tuple_size_v; - using FieldType = std::decay_t::type>; + using FieldType = std::decay_t::type>; - using NewNamedTupleType = - std::conditional_t<_name == FieldType::name_, _NewNamedTupleType, - define_named_tuple_t<_NewNamedTupleType, FieldType>>; + using NewNamedTupleType = + std::conditional_t<_name == FieldType::name_, _NewNamedTupleType, + define_named_tuple_t<_NewNamedTupleType, FieldType>>; - using type = typename remove_single_field::type; + using type = typename remove_single_field::type; }; /// Recursively removes all of the fields signified by _head and _tail from the @@ -53,28 +53,28 @@ struct remove_fields; /// Special case - only head is left. template struct remove_fields<_NamedTupleType, _head> { - using NamedTupleType = std::decay_t<_NamedTupleType>; + using NamedTupleType = std::decay_t<_NamedTupleType>; - constexpr static int num_fields = - std::tuple_size{}; + constexpr static int num_fields = + std::tuple_size_v; - using type = typename remove_single_field, num_fields>::type; + using type = typename remove_single_field, + num_fields>::type; }; /// General case. template struct remove_fields { - using NamedTupleType = std::decay_t<_NamedTupleType>; + using NamedTupleType = std::decay_t<_NamedTupleType>; - constexpr static int num_fields = - std::tuple_size{}; + constexpr static int num_fields = + std::tuple_size_v; - using NewNamedTupleType = - typename remove_single_field, - num_fields>::type; + using NewNamedTupleType = + typename remove_single_field, + num_fields>::type; - using type = typename remove_fields::type; + using type = typename remove_fields::type; }; } // namespace internal diff --git a/include/rfl/internal/tup_to_ptr_tuple.hpp b/include/rfl/internal/tup_to_ptr_tuple.hpp index 7a961c4d..63795238 100644 --- a/include/rfl/internal/tup_to_ptr_tuple.hpp +++ b/include/rfl/internal/tup_to_ptr_tuple.hpp @@ -14,7 +14,7 @@ namespace internal { template auto tup_to_ptr_tuple(TupleType& _t, AlreadyExtracted... _a) { constexpr auto i = sizeof...(AlreadyExtracted); - constexpr auto size = std::tuple_size{}; + constexpr auto size = std::tuple_size_v; if constexpr (i == size) { return std::make_tuple(_a...);