Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions include/iris/x4/rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,16 @@ struct narrowing_checker
requires requires(T&& t) { { Dest{std::forward<T>(t)} }; };
};


template<class Exposed, class RuleAttr>
concept RuleAttrNeedsNarrowingConversion =
concept RuleAttrConvertible =
X4Attribute<RuleAttr> &&
!requires {
std::is_assignable_v<unwrap_container_appender_t<std::remove_const_t<Exposed>>&, RuleAttr>;

template<class Exposed, class RuleAttr>
concept RuleAttrConvertibleWithoutNarrowing =
RuleAttrConvertible<Exposed, RuleAttr> &&
requires {
narrowing_checker<
unwrap_container_appender_t<std::remove_const_t<Exposed>>
>::operator()(std::declval<RuleAttr>());
Expand All @@ -366,8 +372,8 @@ concept RuleAttrTransformable =
X4Attribute<std::remove_const_t<Exposed>> &&
X4Attribute<RuleAttr> &&
std::default_initializable<RuleAttr> &&
std::is_assignable_v<unwrap_container_appender_t<std::remove_const_t<Exposed>>&, RuleAttr> &&
!RuleAttrNeedsNarrowingConversion<
RuleAttrConvertible<Exposed, RuleAttr> &&
RuleAttrConvertibleWithoutNarrowing<
unwrap_container_appender_t<std::remove_const_t<Exposed>>,
RuleAttr
>;
Expand Down Expand Up @@ -434,7 +440,6 @@ struct rule : parser<rule<RuleID, RuleAttr, ForceAttr>>

} else {
static_assert(detail::RuleAttrTransformable<Exposed, RuleAttr>);
static_assert(!detail::RuleAttrNeedsNarrowingConversion<Exposed, RuleAttr>);

// TODO: specialize `container_appender` case, do not create temporary

Expand All @@ -461,10 +466,12 @@ struct rule : parser<rule<RuleID, RuleAttr, ForceAttr>>
requires
(!std::same_as<std::remove_const_t<Exposed>, unused_type>) &&
(!detail::RuleAttrCompatible<Exposed, RuleAttr>) &&
detail::RuleAttrNeedsNarrowingConversion<Exposed, RuleAttr>
detail::RuleAttrConvertible<Exposed, RuleAttr> &&
(!detail::RuleAttrConvertibleWithoutNarrowing<Exposed, RuleAttr>)
[[nodiscard]] constexpr bool
parse(It&, Se const&, Context const&, Exposed&) const = delete; // Rule attribute needs narrowing conversion


template<std::forward_iterator It, std::sentinel_for<It> Se, class Context>
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, unused_type const&) const
Expand Down