diff --git a/include/iris/x4/core/detail/parse_alternative.hpp b/include/iris/x4/core/detail/parse_alternative.hpp index 0cb5f9203..7162d07ec 100644 --- a/include/iris/x4/core/detail/parse_alternative.hpp +++ b/include/iris/x4/core/detail/parse_alternative.hpp @@ -230,7 +230,7 @@ struct parse_into_container_impl> using parser_type = alternative; template Se, class Context, X4Attribute Attr> - requires traits::is_variant_v> + requires traits::is_variant_v::type> [[nodiscard]] static constexpr bool call( parser_type const& parser, @@ -242,7 +242,7 @@ struct parse_into_container_impl> } template Se, class Context, X4Attribute Attr> - requires (!traits::is_variant_v>) + requires (!traits::is_variant_v::type>) [[nodiscard]] static constexpr bool call( parser_type const& parser, diff --git a/include/iris/x4/core/detail/parse_into_container.hpp b/include/iris/x4/core/detail/parse_into_container.hpp index 0da6f707a..2593828b7 100644 --- a/include/iris/x4/core/detail/parse_into_container.hpp +++ b/include/iris/x4/core/detail/parse_into_container.hpp @@ -48,8 +48,7 @@ struct parse_into_container_base_impl { static_assert(!std::same_as, unused_container_type>); - using value_type = traits::container_value_t>; - value_type val; // default-initialize + typename traits::container_value>::type val{}; // value-initialize //static_assert(Parsable); if (!parser.parse(first, last, ctx, val)) return false; @@ -149,7 +148,7 @@ struct parse_into_container_impl It, Se, Context, typename parser_traits::attribute_type >::actual_type, - traits::container_value_t + typename traits::container_value::type >> >; @@ -217,7 +216,7 @@ parse_into_container( using attribute_type = parser_traits::attribute_type; // e.g. `std::string` when the attribute_type is `char` - using substitute_type = traits::variant_find_substitute_t>; + using substitute_type = traits::variant_find_substitute_t::type>; // instead of creating a temporary `substitute_type`, append directly into the emplaced alternative auto& variant_alt = attr.template emplace(); diff --git a/include/iris/x4/core/detail/parse_sequence.hpp b/include/iris/x4/core/detail/parse_sequence.hpp index 28df3abf1..61242686f 100644 --- a/include/iris/x4/core/detail/parse_sequence.hpp +++ b/include/iris/x4/core/detail/parse_sequence.hpp @@ -284,7 +284,7 @@ struct parse_into_container_impl> template static constexpr bool is_container_substitute = traits::is_substitute_v< typename sequence::attribute_type, - traits::container_value_t + typename traits::container_value::type >; template Se, class Context, X4Attribute Attr> diff --git a/include/iris/x4/directive/repeat.hpp b/include/iris/x4/directive/repeat.hpp index 9dc8db3c2..5bf43d63d 100644 --- a/include/iris/x4/directive/repeat.hpp +++ b/include/iris/x4/directive/repeat.hpp @@ -87,7 +87,7 @@ template struct repeat_directive : proxy_parser> { using base_type = proxy_parser; - using attribute_type = traits::build_container_t::attribute_type>; + using attribute_type = traits::build_container::attribute_type>::type; static constexpr bool handles_container = true; diff --git a/include/iris/x4/operator/alternative.hpp b/include/iris/x4/operator/alternative.hpp index 03015241a..2746a15e5 100644 --- a/include/iris/x4/operator/alternative.hpp +++ b/include/iris/x4/operator/alternative.hpp @@ -29,6 +29,27 @@ namespace iris::x4 { +namespace detail { + +template +struct alternative_attribute_impl; + +// Both same attribute +template +struct alternative_attribute_impl +{ + using type = parser_traits::attribute_type; +}; + +// Not same attribute +template +struct alternative_attribute_impl +{ + using type = traits::detail::attribute_of_alternative::type; +}; + +} // detail + template struct alternative : binary_parser> { @@ -40,10 +61,8 @@ struct alternative : binary_parser> public: // Canonicalize `rvariant` to `X` - using attribute_type = std::conditional_t< - is_both_same_attribute, - std::type_identity::attribute_type>, - traits::attribute_of_binary + using attribute_type = detail::alternative_attribute_impl< + is_both_same_attribute, Left, Right >::type; // If canonicalized, proxy the underlying `sequence_size`. In other words: diff --git a/include/iris/x4/operator/kleene.hpp b/include/iris/x4/operator/kleene.hpp index 1785f3935..0289ce968 100644 --- a/include/iris/x4/operator/kleene.hpp +++ b/include/iris/x4/operator/kleene.hpp @@ -28,7 +28,7 @@ namespace iris::x4 { template struct kleene : unary_parser> { - using attribute_type = traits::build_container_t::attribute_type>; + using attribute_type = traits::build_container::attribute_type>::type; static constexpr bool handles_container = true; diff --git a/include/iris/x4/operator/list.hpp b/include/iris/x4/operator/list.hpp index 9270aa6d7..c6d9039b9 100644 --- a/include/iris/x4/operator/list.hpp +++ b/include/iris/x4/operator/list.hpp @@ -28,7 +28,7 @@ namespace iris::x4 { template struct list : binary_parser> { - using attribute_type = traits::build_container_t::attribute_type>; + using attribute_type = traits::build_container::attribute_type>::type; static constexpr bool handles_container = true; diff --git a/include/iris/x4/operator/optional.hpp b/include/iris/x4/operator/optional.hpp index a259a33fa..498b30f87 100644 --- a/include/iris/x4/operator/optional.hpp +++ b/include/iris/x4/operator/optional.hpp @@ -30,7 +30,7 @@ namespace iris::x4 { template struct optional : unary_parser> { - using attribute_type = traits::build_optional_t::attribute_type>; + using attribute_type = traits::build_optional::attribute_type>::type; static constexpr bool handles_container = true; @@ -82,15 +82,13 @@ struct optional : unary_parser> [[nodiscard]] constexpr bool parse(It& first, Se const& last, Context const& ctx, Attr& attr) const noexcept( - std::is_nothrow_default_constructible_v> && - is_nothrow_parsable_v> && - noexcept(x4::move_to(std::declval&&>(), attr)) + std::is_nothrow_default_constructible_v::type> && + is_nothrow_parsable_v::type> && + noexcept(x4::move_to(std::declval::type&&>(), attr)) ) { - using value_type = x4::traits::optional_value_t; - value_type val; // default-initialize + typename traits::optional_value::type val{}; // value-initialize - static_assert(Parsable); if (this->subject.parse(first, last, ctx, val)) { // assign the parsed value into our attribute x4::move_to(std::move(val), attr); diff --git a/include/iris/x4/operator/plus.hpp b/include/iris/x4/operator/plus.hpp index 45f1ce0e9..4b16ca713 100644 --- a/include/iris/x4/operator/plus.hpp +++ b/include/iris/x4/operator/plus.hpp @@ -28,7 +28,7 @@ namespace iris::x4 { template struct plus : unary_parser> { - using attribute_type = traits::build_container_t::attribute_type>; + using attribute_type = traits::build_container::attribute_type>::type; static constexpr bool handles_container = true; diff --git a/include/iris/x4/operator/sequence.hpp b/include/iris/x4/operator/sequence.hpp index 3b9b91b90..67109b1a9 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::detail::attribute_of_sequence::type; static constexpr std::size_t sequence_size = parser_traits::sequence_size + parser_traits::sequence_size; diff --git a/include/iris/x4/string/detail/string_parse.hpp b/include/iris/x4/string/detail/string_parse.hpp index c027248d0..945a6a732 100644 --- a/include/iris/x4/string/detail/string_parse.hpp +++ b/include/iris/x4/string/detail/string_parse.hpp @@ -32,7 +32,7 @@ string_parse( { using synthesized_value_type = traits::synthesized_value_t; static_assert(std::same_as, traits::container_attr>); - using value_type = traits::container_value_t; + using value_type = traits::container_value::type; static_assert(!traits::CharLike || std::same_as, "Mixing incompatible char types is not allowed"); It it = first; @@ -79,7 +79,7 @@ string_parse( { using synthesized_value_type = traits::synthesized_value_t; static_assert(std::same_as, traits::container_attr>); - using value_type = traits::container_value_t; + using value_type = traits::container_value::type; static_assert(!traits::CharLike || std::same_as, "Mixing incompatible char types is not allowed"); auto uc_it = ucstr.begin(); diff --git a/include/iris/x4/traits/attribute_of_binary.hpp b/include/iris/x4/traits/attribute_of_binary.hpp index ffd60eb94..87fd59bae 100644 --- a/include/iris/x4/traits/attribute_of_binary.hpp +++ b/include/iris/x4/traits/attribute_of_binary.hpp @@ -12,108 +12,113 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include #include #include #include // TODO: move iris::type_list to separate header -#include - namespace iris::x4::traits { namespace detail { -template -struct append_to_type_list {}; - -template -using append_to_type_list_t = append_to_type_list::type; - -template -struct append_to_type_list> -{ - using type = type_list; -}; +template +struct concat_type_list; template -struct append_to_type_list, unused_type, Us...> - : append_to_type_list, Us...> -{}; - -template -struct append_to_type_list, U, Us...> - : append_to_type_list, Us...> -{}; - -template -struct append_to_type_list, type_list, Vs...> - : append_to_type_list, Us...>, Vs...> -{}; - -template class TupleTT, class T> -struct tuple_to_type_list; - -template class TupleTT, class T> -using tuple_to_type_list_t = tuple_to_type_list::type; - -template class TupleTT, class T> -struct tuple_to_type_list -{ - using type = T; -}; - -template class TupleTT, class... Ts> -struct tuple_to_type_list> +struct concat_type_list, type_list> { - using type = 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 {}; +#if 0 +#define IRIS_X4_TRAITS_DETAIL_DEFINE_TYPE_LIST_CONV(postfix, tmpl) \ + template \ + struct to_type_list_##postfix \ + { \ + using type = type_list; \ + }; \ + template<> \ + struct to_type_list_##postfix \ + { \ + using type = type_list<>; \ + }; \ + template \ + struct to_type_list_##postfix> \ + { \ + using type = type_list; \ + }; \ + \ + template \ + struct from_type_list_##postfix {}; \ + template<> \ + struct from_type_list_##postfix> \ + { \ + using type = unused_type; \ + }; \ + template \ + struct from_type_list_##postfix> \ + { \ + using type = T; \ + }; \ + template \ + struct from_type_list_##postfix> \ + { \ + using type = tmpl; \ + }; \ + \ + template \ + struct attribute_of_##postfix { \ + using type = detail::from_type_list_##postfix< \ + typename detail::concat_type_list< \ + typename detail::to_type_list_##postfix::attribute_type>::type, \ + typename detail::to_type_list_##postfix::attribute_type>::type \ + >::type \ + >::type; \ + }; +#endif -template class TupleTT> -struct type_list_to_tuple> -{ +// +// AUTOGENERATED CODE; DO NOT EDIT. +// Expanded using Visual Studio's "Expand Inline" feature. +// Code style is kept as-is. +// + +// IRIS_X4_TRAITS_DETAIL_DEFINE_TYPE_LIST_CONV(sequence, alloy::tuple) +template struct to_type_list_sequence { + using type = type_list; +}; template<> struct to_type_list_sequence { + using type = type_list<>; +}; template struct to_type_list_sequence> { + using type = type_list; +}; template struct from_type_list_sequence {}; template<> struct from_type_list_sequence> { using type = unused_type; -}; - -template class TupleTT, class T> -struct type_list_to_tuple> -{ +}; template struct from_type_list_sequence> { using type = T; +}; template struct from_type_list_sequence> { + using type = alloy::tuple; +}; template struct attribute_of_sequence { + using type = detail::from_type_list_sequence< typename detail::concat_type_list< typename detail::to_type_list_sequence::attribute_type>::type, typename detail::to_type_list_sequence::attribute_type>::type >::type >::type; }; -template class TupleTT, class T0, class T1, class... Ts> -struct type_list_to_tuple> -{ - using type = TupleTT; +// IRIS_X4_TRAITS_DETAIL_DEFINE_TYPE_LIST_CONV(alternative, rvariant) +template struct to_type_list_alternative { + using type = type_list; +}; template<> struct to_type_list_alternative { + using type = type_list<>; +}; template struct to_type_list_alternative> { + using type = type_list; +}; template struct from_type_list_alternative {}; template<> struct from_type_list_alternative> { + using type = unused_type; +}; template struct from_type_list_alternative> { + using type = T; +}; template struct from_type_list_alternative> { + using type = rvariant; +}; template struct attribute_of_alternative { + using type = detail::from_type_list_alternative< typename detail::concat_type_list< typename detail::to_type_list_alternative::attribute_type>::type, typename detail::to_type_list_alternative::attribute_type>::type >::type >::type; }; -template class TupleTT, class TypeList> -using type_list_to_tuple_t = type_list_to_tuple::type; - } // detail -template< - template class TupleTT, - class LeftParser, class RightParser -> -struct attribute_of_binary -{ - 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 #endif diff --git a/include/iris/x4/traits/container_traits.hpp b/include/iris/x4/traits/container_traits.hpp index b768b1fc5..b48db67e7 100644 --- a/include/iris/x4/traits/container_traits.hpp +++ b/include/iris/x4/traits/container_traits.hpp @@ -84,9 +84,6 @@ struct container_value : detail::remove_value_const {}; -template -using container_value_t = typename container_value::type; - template struct container_value : container_value {}; @@ -476,9 +473,6 @@ struct build_container using type = std::vector; }; -template -using build_container_t = typename build_container::type; - template struct build_container> : build_container {}; diff --git a/include/iris/x4/traits/optional_traits.hpp b/include/iris/x4/traits/optional_traits.hpp index 036798150..ab7b4d803 100644 --- a/include/iris/x4/traits/optional_traits.hpp +++ b/include/iris/x4/traits/optional_traits.hpp @@ -41,9 +41,6 @@ struct build_optional using type = std::optional; }; -template -using build_optional_t = typename build_optional::type; - template struct build_optional> { @@ -69,9 +66,6 @@ struct optional_value using type = typename T::value_type; }; -template -using optional_value_t = typename optional_value::type; - template<> struct optional_value { diff --git a/include/iris/x4/traits/substitution.hpp b/include/iris/x4/traits/substitution.hpp index d8c04a51d..f675231ea 100644 --- a/include/iris/x4/traits/substitution.hpp +++ b/include/iris/x4/traits/substitution.hpp @@ -52,7 +52,7 @@ struct is_all_substitute_for_tuple : is_all_substitute_for_tuple template struct value_type_is_substitute - : is_substitute, container_value_t> + : is_substitute::type, typename container_value::type> {}; template diff --git a/modules/iris b/modules/iris index 32d9fd929..cec583eed 160000 --- a/modules/iris +++ b/modules/iris @@ -1 +1 @@ -Subproject commit 32d9fd9299bff648b9852b1bb822f2c53cbd62f2 +Subproject commit cec583eed7ab2fb70e7ef6aa52ab840bc03e92ca