diff --git a/include/iris/x4/operator/alternative.hpp b/include/iris/x4/operator/alternative.hpp index d4f9b9b71..91ff59d5e 100644 --- a/include/iris/x4/operator/alternative.hpp +++ b/include/iris/x4/operator/alternative.hpp @@ -31,7 +31,7 @@ namespace iris::x4 { template struct alternative : binary_parser> { - using attribute_type = traits::attribute_of_binary::type; + using attribute_type = traits::attribute_of_binary::type; using binary_parser::binary_parser; diff --git a/include/iris/x4/operator/sequence.hpp b/include/iris/x4/operator/sequence.hpp index 0b69a4509..74a7aaea3 100644 --- a/include/iris/x4/operator/sequence.hpp +++ b/include/iris/x4/operator/sequence.hpp @@ -31,7 +31,7 @@ namespace iris::x4 { template struct sequence : binary_parser> { - using attribute_type = traits::attribute_of_binary::type; + using attribute_type = traits::attribute_of_binary::type; static constexpr std::size_t sequence_size = parser_traits::sequence_size + parser_traits::sequence_size; diff --git a/include/iris/x4/traits/attribute_of_binary.hpp b/include/iris/x4/traits/attribute_of_binary.hpp index 0628e2429..6e7b4a109 100644 --- a/include/iris/x4/traits/attribute_of_binary.hpp +++ b/include/iris/x4/traits/attribute_of_binary.hpp @@ -16,81 +16,102 @@ #include #include +#include // TODO: move iris::type_list to separate header + #include namespace iris::x4::traits { namespace detail { -template -struct type_sequence -{ - using type = type_sequence; - - static constexpr std::size_t size = sizeof...(Ts); - - template - using prepend = type_sequence; +template +struct append_to_type_list {}; - template - using extend = U::template prepend; +template +using append_to_type_list_t = append_to_type_list::type; - template class U> - using transfer_to = U; +template +struct append_to_type_list> +{ + using type = type_list; }; -template -struct types_of_binary_init : type_sequence +template +struct append_to_type_list, unused_type, Us...> + : append_to_type_list, Us...> {}; -template<> -struct types_of_binary_init : type_sequence<> +template +struct append_to_type_list, U, Us...> + : append_to_type_list, Us...> {}; -template<> -struct types_of_binary_init : type_sequence<> +template +struct append_to_type_list, type_list, Vs...> + : append_to_type_list, Us...>, Vs...> {}; -template class BinaryParserTT, class ParserT> -struct get_types_of_binary - : types_of_binary_init::attribute_type> // TODO: unwrap -{}; +template class TupleTT, class T> +struct tuple_to_type_list; -template class BinaryParserTT, class Left, class Right> -struct get_types_of_binary> - : get_types_of_binary::template extend> -{}; +template class TupleTT, class T> +using tuple_to_type_list_t = tuple_to_type_list::type; -template class AttrTT, class T, std::size_t = T::size> -struct type_sequence_to_attribute +template class TupleTT, class T> +struct tuple_to_type_list { - using type = typename T::template transfer_to; + using type = T; }; -template class AttrTT, class T> -struct type_sequence_to_attribute - : T::template transfer_to -{}; +template class TupleTT, class... Ts> +struct tuple_to_type_list> +{ + using type = type_list...>; +}; + +template class TupleTT, class T> +using tuple_to_type_list_t = tuple_to_type_list::type; + +template class TupleTT, class TypeList> +struct type_list_to_tuple {}; -template class AttrTT, class T> -struct type_sequence_to_attribute +template class TupleTT> +struct type_list_to_tuple> { using type = unused_type; }; +template class TupleTT, class T> +struct type_list_to_tuple> +{ + using type = T; +}; + +template class TupleTT, class T0, class T1, class... Ts> +struct type_list_to_tuple> +{ + using type = TupleTT; +}; + +template class TupleTT, class TypeList> +using type_list_to_tuple_t = type_list_to_tuple::type; + } // detail template< - template class AttrTT, - template class BinaryParserTT, - class Left, class Right + template class TupleTT, + class LeftParser, class RightParser > struct attribute_of_binary { - using type = detail::type_sequence_to_attribute< - AttrTT, - typename detail::get_types_of_binary>::type - >::type; + using type = detail::type_list_to_tuple_t< + TupleTT, + detail::append_to_type_list_t< + type_list<>, + detail::tuple_to_type_list_t::attribute_type>, + detail::tuple_to_type_list_t::attribute_type> + > + >; }; } // iris::x4::traits