From 6ebb7f69b9bc62015bc5a6c6f51bd93e1fdb9544 Mon Sep 17 00:00:00 2001 From: Vasiliy Olekhov Date: Thu, 12 Dec 2024 11:22:46 +0200 Subject: [PATCH] wip --- .../core/include/nil/detail/type_traits.hpp | 17 +++---- .../nil/marshalling/algorithms/pack.hpp | 50 +++++++++---------- .../nil/marshalling/detail/pack_value.hpp | 6 +-- .../nil/marshalling/processing/tuple.hpp | 34 ++++++------- .../num_value_multi_range_validator.hpp | 4 +- .../nil/marshalling/types/array_list.hpp | 2 +- .../include/nil/marshalling/types/bundle.hpp | 2 +- .../marshalling/types/bundle/basic_type.hpp | 2 +- 8 files changed, 56 insertions(+), 61 deletions(-) diff --git a/crypto3/libs/marshalling/core/include/nil/detail/type_traits.hpp b/crypto3/libs/marshalling/core/include/nil/detail/type_traits.hpp index f1e7c38a9c..7c57066c01 100644 --- a/crypto3/libs/marshalling/core/include/nil/detail/type_traits.hpp +++ b/crypto3/libs/marshalling/core/include/nil/detail/type_traits.hpp @@ -206,16 +206,15 @@ }; #endif -namespace nil::crypto3 { +namespace nil::crypto3::marshalling { namespace detail { -// GENERATE_HAS_MEMBER_TYPE(iterator) -// GENERATE_HAS_MEMBER_TYPE(const_iterator) + GENERATE_HAS_MEMBER_TYPE(iterator) + GENERATE_HAS_MEMBER_TYPE(const_iterator) -// GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION(begin, const_iterator) -// GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION(end, const_iterator) + GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION(begin, const_iterator) + GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION(end, const_iterator) - /* template struct is_iterator { static char test(...); @@ -228,22 +227,18 @@ namespace nil::crypto3 { static long test(U &&); constexpr static bool value = std::is_same())), long>::value; - };*/ + }; - /* template struct is_range { static const bool value = has_begin::value && has_end::value; }; - */ - /* template struct is_container { static const bool value = has_const_iterator::value && has_begin::value && has_end::value; }; - */ /// @brief Check whether provided type is a variant of /// std::tuple. diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/algorithms/pack.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/algorithms/pack.hpp index 9550ae8363..5a6f207318 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/algorithms/pack.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/algorithms/pack.hpp @@ -60,7 +60,7 @@ namespace nil::crypto3 { */ template typename std::enable_if< - nil::crypto3::detail::is_range::value, + detail::is_range::value, detail::range_repack_impl>::type pack(const SinglePassRange &val, status_type &status) { @@ -69,7 +69,7 @@ namespace nil::crypto3 { } template - typename std::enable_if::value, + typename std::enable_if::value, detail::value_repack_impl>::type pack(const TInput &val, status_type &status) { @@ -93,7 +93,7 @@ namespace nil::crypto3 { */ template typename std::enable_if< - nil::crypto3::detail::is_iterator::value + detail::is_iterator::value && std::is_integral::value_type>::value, detail::range_repack_impl>::type pack(InputIterator first, InputIterator last, status_type &status) { @@ -102,7 +102,7 @@ namespace nil::crypto3 { } template - typename std::enable_if::value && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value && detail::is_iterator::value, TOutputIterator>::type pack(const TInput &val, TOutputIterator out, status_type &status) { using T = typename std::iterator_traits::value_type; @@ -111,8 +111,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value + && detail::is_iterator::value, TOutputIterator>::type pack(const SinglePassRange &rng_input, TOutputIterator out, status_type &status) { BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept)); @@ -122,8 +122,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value + && detail::is_iterator::value, TOutputIterator>::type pack(InputIterator first, InputIterator last, TOutputIterator out, status_type &status) { using T = typename std::iterator_traits::value_type; @@ -132,7 +132,7 @@ namespace nil::crypto3 { } template - typename std::enable_if::value && nil::crypto3::detail::is_range::value + typename std::enable_if::value && detail::is_range::value && std::is_constructible::const_iterator, typename std::vector::const_iterator>::value, @@ -147,7 +147,7 @@ namespace nil::crypto3 { } template - typename std::enable_if::value && nil::crypto3::detail::is_range::value + typename std::enable_if::value && detail::is_range::value && !std::is_constructible::const_iterator, typename std::vector::const_iterator>::value, @@ -161,8 +161,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_range::value + typename std::enable_if::value + && detail::is_range::value && std::is_constructible::value, @@ -179,7 +179,7 @@ namespace nil::crypto3 { template typename std::enable_if< - nil::crypto3::detail::is_range::value && nil::crypto3::detail::is_range::value + detail::is_range::value && detail::is_range::value && !std::is_constructible< SinglePassRange2, typename std::vector::const_iterator, @@ -195,7 +195,7 @@ namespace nil::crypto3 { template typename std::enable_if< - nil::crypto3::detail::is_iterator::value && nil::crypto3::detail::is_range::value + detail::is_iterator::value && detail::is_range::value && std::is_constructible< SinglePassRange, typename std::vector::const_iterator, @@ -211,8 +211,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_range::value + typename std::enable_if::value + && detail::is_range::value && !std::is_constructible::value, @@ -225,8 +225,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && !(nil::crypto3::detail::is_range::value || nil::crypto3::detail::is_array::value) + typename std::enable_if::value + && !(detail::is_range::value || detail::is_array::value) && !std::is_same::value, status_type>::type pack(InputIterator first, InputIterator last, TOutput &rng_output) { @@ -237,8 +237,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && !(nil::crypto3::detail::is_range::value || nil::crypto3::detail::is_array::value) + typename std::enable_if::value + && !(detail::is_range::value || detail::is_array::value) && !std::is_same::value, status_type>::type pack(const SinglePassRange &rng_input, TOutput &rng_output) { @@ -249,7 +249,7 @@ namespace nil::crypto3 { } template - typename std::enable_if::value && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value && detail::is_iterator::value, status_type>::type pack(const TInput &val, TOutputIterator out) { @@ -261,8 +261,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value + && detail::is_iterator::value, status_type>::type pack(const SinglePassRange &rng_input, TOutputIterator out) { BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept)); @@ -274,8 +274,8 @@ namespace nil::crypto3 { } template - typename std::enable_if::value - && nil::crypto3::detail::is_iterator::value, + typename std::enable_if::value + && detail::is_iterator::value, status_type>::type pack(InputIterator first, InputIterator last, TOutputIterator out) { using T = typename std::iterator_traits::value_type; diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/detail/pack_value.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/detail/pack_value.hpp index 12ec480770..aa6e5eabf9 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/detail/pack_value.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/detail/pack_value.hpp @@ -92,7 +92,7 @@ namespace nil::crypto3 { template::template type<>>::value>::type> + !detail::is_container::template type<>>::value>::type> inline operator std::array() { return similar_std_array_marshalling>(); @@ -100,7 +100,7 @@ namespace nil::crypto3 { template::template type<>>::value>::type> + !detail::is_container::template type<>>::value>::type> inline operator boost::array() { return similar_std_array_marshalling>(); @@ -131,7 +131,7 @@ namespace nil::crypto3 { template::value && !is_marshalling_type::value + detail::is_range::value && !is_marshalling_type::value && !nil::crypto3::marshalling::is_container::template type<>>::value>::type> inline operator OutputRange() { diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/processing/tuple.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/processing/tuple.hpp index 992278bd7b..239eeea356 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/processing/tuple.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/processing/tuple.hpp @@ -47,7 +47,7 @@ namespace nil::crypto3 { template struct tuple_as_aligned_union { /// @cond DOCUMENT_STATIC_ASSERT - static_assert(::nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); /// @endcond /// @brief Type definition is invalid for any type that is not @@ -72,7 +72,7 @@ namespace nil::crypto3 { /// @brief Check whether tuple is unique, i.e. doesn't have contain types. template struct tuple_is_unique { - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); /// @brief Value is set to true when tuple is discovered to be unique. static const bool value = false; @@ -81,7 +81,7 @@ namespace nil::crypto3 { /// @cond SKIP_DOC template struct tuple_is_unique> { - static const bool value = (!nil::crypto3::detail::is_in_tuple>::value) + static const bool value = (!marshalling::detail::is_in_tuple>::value) && tuple_is_unique>::value; }; @@ -103,7 +103,7 @@ namespace nil::crypto3 { template static void exec(TTuple &&tuple, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static const std::size_t OffsetedRem = TRem + TOff; static_assert(OffsetedRem <= TupleSize, "Incorrect parameters"); @@ -220,7 +220,7 @@ namespace nil::crypto3 { template static void exec(TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static_assert(TRem <= TupleSize, "Incorrect TRem"); @@ -276,7 +276,7 @@ namespace nil::crypto3 { template static void exec(TTuple &&tuple, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static_assert(TRem <= TupleSize, "Incorrect TRem"); @@ -332,7 +332,7 @@ namespace nil::crypto3 { template static void exec(TTuple &&tuple, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static_assert(TRem <= TupleSize, "Incorrect TRem"); @@ -397,7 +397,7 @@ namespace nil::crypto3 { template static constexpr TValue exec(TTuple &&tuple, const TValue &value, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static_assert((TOff + TRem) <= std::tuple_size::value, "Incorrect params"); return tuple_accumulate_helper::exec( @@ -482,7 +482,7 @@ namespace nil::crypto3 { template static constexpr TValue exec(const TValue &value, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static_assert((TOff + TRem) <= std::tuple_size::value, "Incorrect TRem"); return tuple_type_accumulate_helper::template exec( @@ -562,8 +562,8 @@ namespace nil::crypto3 { /// @tparam TSecond Type of the second tuple. template struct tuple_cat { - static_assert(nil::crypto3::detail::is_tuple::value, "TFirst must be tuple"); - static_assert(nil::crypto3::detail::is_tuple::value, "TSecond must be tuple"); + static_assert(marshalling::detail::is_tuple::value, "TFirst must be tuple"); + static_assert(marshalling::detail::is_tuple::value, "TSecond must be tuple"); /// @brief Result type of tuples concatenation. using type = typename std::decay(), @@ -588,7 +588,7 @@ namespace nil::crypto3 { template static void exec(std::size_t idx, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static_assert(TCount <= TupleSize, "Incorrect TCount"); static_assert(0U < TCount, "Incorrect instantiation"); @@ -653,7 +653,7 @@ namespace nil::crypto3 { template void tuple_for_selected_type(std::size_t idx, TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "Provided tupe must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "Provided tupe must be std::tuple"); static const std::size_t TupleSize = std::tuple_size::value; static_assert(0U < TupleSize, "Empty tuples are not supported"); @@ -694,8 +694,8 @@ namespace nil::crypto3 { /// @tparam TTuple Containing tuple template constexpr bool tuple_is_tail_of() { - static_assert(nil::crypto3::detail::is_tuple::value, "TTail param must be tuple"); - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple param must be tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTail param must be tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple param must be tuple"); return std::tuple_size::value <= std::tuple_size::value && detail::tuple_tail_check_helpler< TTail, TTuple, std::tuple_size::value - std::tuple_size::value>::value; @@ -712,7 +712,7 @@ namespace nil::crypto3 { template static constexpr bool check(TFunc &&func) { using Tuple = typename std::decay::type; - static_assert(nil::crypto3::detail::is_tuple::value, "TTuple must be std::tuple"); + static_assert(marshalling::detail::is_tuple::value, "TTuple must be std::tuple"); static_assert(TRem <= std::tuple_size::value, "Incorrect TRem"); using ElemType = typename std::tuple_element::value - TRem, Tuple>::type; return @@ -740,7 +740,7 @@ namespace nil::crypto3 { template constexpr bool tuple_type_is_any_of(TFunc &&func) { - static_assert(nil::crypto3::detail::is_tuple::value, "Tuple as argument is expected"); + static_assert(marshalling::detail::is_tuple::value, "Tuple as argument is expected"); return detail::tuple_type_is_any_of_helper::value>::template check( std::forward(func)); } diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/types/adapter/num_value_multi_range_validator.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/types/adapter/num_value_multi_range_validator.hpp index ecd41d36f1..deeb5ea09b 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/types/adapter/num_value_multi_range_validator.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/types/adapter/num_value_multi_range_validator.hpp @@ -39,7 +39,7 @@ namespace nil::crypto3 { class num_value_multi_range_validator : public TBase { using base_impl_type = TBase; - static_assert(nil::crypto3::detail::is_tuple::value, "TRanges must be a tuple"); + static_assert(marshalling::detail::is_tuple::value, "TRanges must be a tuple"); public: using value_type = typename base_impl_type::value_type; @@ -79,7 +79,7 @@ namespace nil::crypto3 { template bool operator()(bool val) const { static_cast(val); - static_assert(nil::crypto3::detail::is_tuple::value, + static_assert(marshalling::detail::is_tuple::value, "TRange must be a tuple"); static_assert(std::tuple_size::value == 2, "Tuple with 2 elements is expected"); using MinVal = typename std::tuple_element<0, TRange>::type; diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/types/array_list.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/types/array_list.hpp index e3248764c0..441f5cb561 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/types/array_list.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/types/array_list.hpp @@ -424,7 +424,7 @@ namespace nil::crypto3 { // Helper functions to convert to/from an arraylist. template typename std::enable_if< - nil::crypto3::detail::is_range::value, + marshalling::detail::is_range::value, standard_array_list>::type fill_standard_array_list( const Range& input_range, diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle.hpp index f3a9abca07..676aa3ed57 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle.hpp @@ -85,7 +85,7 @@ namespace nil::crypto3 { template class bundle : private detail::adapt_basic_field_type, TOptions...> { using base_impl_type = detail::adapt_basic_field_type, TOptions...>; - static_assert(nil::crypto3::detail::is_tuple::value, + static_assert(marshalling::detail::is_tuple::value, "TMembers is expected to be a tuple of std::tuple<...>"); static_assert(1U <= std::tuple_size::value, diff --git a/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle/basic_type.hpp b/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle/basic_type.hpp index 5c7232cc9f..225205f6c2 100644 --- a/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle/basic_type.hpp +++ b/crypto3/libs/marshalling/core/include/nil/marshalling/types/bundle/basic_type.hpp @@ -407,7 +407,7 @@ namespace nil::crypto3 { return write_no_status_helper(iter); } - static_assert(nil::crypto3::detail::is_tuple::value, + static_assert(marshalling::detail::is_tuple::value, "value_type must be tuple"); value_type members_; };