From 653cb61d553605262bea9d5c1104befb980b97db Mon Sep 17 00:00:00 2001 From: Nana Sakisaka <1901813+saki7@users.noreply.github.com> Date: Mon, 14 Sep 2026 00:14:05 +0900 Subject: [PATCH] Refactor some facilities --- include/iris/x4/attribute/as.hpp | 3 +-- include/iris/x4/core/action.hpp | 4 ++-- include/iris/x4/directive/with.hpp | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/iris/x4/attribute/as.hpp b/include/iris/x4/attribute/as.hpp index 6ddc50f7c..8c9aa32b3 100644 --- a/include/iris/x4/attribute/as.hpp +++ b/include/iris/x4/attribute/as.hpp @@ -104,8 +104,7 @@ struct as_type_parser : unary_parser> // `outer_parser(as(subject))` forwards temporary `T` local variable for the subject, then move the variable to `U&` template Se, class Context, X4NonUnusedAttribute OuterAttr> requires - (!std::same_as, T>) && - X4Movable + (!std::same_as, T>) [[nodiscard]] constexpr bool parse(It& first, Se const& last, Context const& ctx, OuterAttr& outer_attr) const noexcept( diff --git a/include/iris/x4/core/action.hpp b/include/iris/x4/core/action.hpp index b3b70234b..6341b4a0d 100644 --- a/include/iris/x4/core/action.hpp +++ b/include/iris/x4/core/action.hpp @@ -94,7 +94,7 @@ struct action : proxy_parser> noexcept(this->parse_main(first, last, ctx, std::declval())) ) { - typename base_type::attribute_type attr_temp; // default-initialize + typename base_type::attribute_type attr_temp{}; // value-initialize return this->parse_main(first, last, ctx, attr_temp); } @@ -138,7 +138,7 @@ struct action : proxy_parser> noexcept(this->parse_main(first, last, ctx, std::declval())) ) { - typename base_type::attribute_type attr_temp; // default-initialize + typename base_type::attribute_type attr_temp{}; // value-initialize return this->parse_main(first, last, ctx, attr_temp); } diff --git a/include/iris/x4/directive/with.hpp b/include/iris/x4/directive/with.hpp index 236b24436..b658d82e4 100644 --- a/include/iris/x4/directive/with.hpp +++ b/include/iris/x4/directive/with.hpp @@ -233,6 +233,8 @@ using parsers::directive::with; template struct without_directive : proxy_parser> { + static_assert(sizeof...(IDs) > 0); + template Se, class Context, X4Attribute Attr> [[nodiscard]] constexpr bool parse(It& first, Se const& last, Context const& ctx, Attr& attr) const @@ -258,9 +260,19 @@ namespace detail { template struct without_gen { + // `without<>(p)` is no-op + template + requires (sizeof...(IDs) == 0) + [[nodiscard]] static constexpr auto&& + operator[](Subject&& subject IRIS_LIFETIMEBOUND) noexcept + { + return static_cast(subject); + } + template - [[nodiscard]] constexpr without_directive, IDs...> - operator[](Subject&& subject) const // TODO: MSVC 2022 does not properly handle static operator[] + requires (sizeof...(IDs) > 0) + [[nodiscard]] static constexpr without_directive, IDs...> + operator[](Subject&& subject) noexcept(std::is_nothrow_constructible_v, IDs...>, Subject>) { return without_directive, IDs...>{