From c41c9aec95f45cc2cbe0d3b65b5cf07f54e7f26b Mon Sep 17 00:00:00 2001 From: Nana Sakisaka <1901813+saki7@users.noreply.github.com> Date: Sat, 13 Sep 2025 08:57:04 +0900 Subject: [PATCH] Revert "Modernize `x3::confix` (#819)" This reverts commit b389b1ce56a50d66c5f1de97fd76de8ec71328d2. --- .../boost/spirit/home/x3/directive/confix.hpp | 130 ++++++------------ test/x3/confix.cpp | 13 +- 2 files changed, 50 insertions(+), 93 deletions(-) diff --git a/include/boost/spirit/home/x3/directive/confix.hpp b/include/boost/spirit/home/x3/directive/confix.hpp index c352bff2d..79d7fb1fa 100644 --- a/include/boost/spirit/home/x3/directive/confix.hpp +++ b/include/boost/spirit/home/x3/directive/confix.hpp @@ -2,7 +2,7 @@ Copyright (c) 2009 Chris Hoeppler Copyright (c) 2014 Lee Clagett Copyright (c) 2017 wanghan02 - Copyright (c) 2024-2025 Nana Sakisaka + Copyright (c) 2024 Nana Sakisaka Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -13,124 +13,82 @@ #include #include -#include -#include -#include -#include - -namespace boost::spirit::x3 +namespace boost { namespace spirit { namespace x3 { template struct confix_directive : unary_parser> { - using base_type = unary_parser>; - static constexpr bool is_pass_through_unary = true; - static constexpr bool handles_container = Subject::handles_container; + typedef unary_parser< + Subject, confix_directive> base_type; + static bool const is_pass_through_unary = true; + static bool const handles_container = Subject::handles_container; - template - requires - std::is_constructible_v && - std::is_constructible_v && - std::is_constructible_v - constexpr confix_directive(PrefixT&& prefix, SubjectT&& subject, PostfixT&& postfix) - noexcept( - std::is_nothrow_constructible_v && - std::is_nothrow_constructible_v && - std::is_nothrow_constructible_v - ) - : base_type(std::forward(subject)) - , prefix_(std::forward(prefix)) - , postfix_(std::forward(postfix)) + constexpr confix_directive(Prefix const& prefix + , Subject const& subject + , Postfix const& postfix) : + base_type(subject), + prefix(prefix), + postfix(postfix) { } - template Se, typename Context, typename RContext, typename Attribute> - [[nodiscard]] constexpr bool - parse( - It& first, Se const& last, Context const& context, RContext& rcontext, Attribute& attr - ) const noexcept( - std::is_nothrow_copy_assignable_v && - is_nothrow_parsable_v && - is_nothrow_parsable_v && - is_nothrow_parsable_v - ) + template + bool parse( + Iterator& first, Iterator const& last + , Context const& context, RContext& rcontext, Attribute& attr) const { - It const saved_first = first; + Iterator save = first; - if (!(prefix_.parse(first, last, context, rcontext, unused) && + if (!(prefix.parse(first, last, context, rcontext, unused) && this->subject.parse(first, last, context, rcontext, attr) && - postfix_.parse(first, last, context, rcontext, unused)) - ) { + postfix.parse(first, last, context, rcontext, unused))) + { #if !BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE - if (x3::has_expectation_failure(context)) + if (has_expectation_failure(context)) { // don't rollback iterator (mimicking exception-like behavior) return false; } #endif - first = saved_first; + first = save; return false; } return true; } - private: - Prefix prefix_; - Postfix postfix_; + Prefix prefix; + Postfix postfix; }; - namespace detail + template + struct confix_gen { - template - struct [[nodiscard]] confix_gen + template + constexpr confix_directive< + Prefix, typename extension::as_parser::value_type, Postfix> + operator[](Subject const& subject) const { - template - [[nodiscard]] constexpr confix_directive, Postfix> - operator[](Subject&& subject) const - noexcept( - is_parser_nothrow_castable_v && - std::is_nothrow_constructible_v< - confix_directive, Postfix>, - Prefix const&, - as_parser_t, - Postfix const& - > - ) - { - return { prefix, as_parser(std::forward(subject)), postfix }; - } + return { prefix, as_parser(subject), postfix }; + } - Prefix prefix; - Postfix postfix; - }; + Prefix prefix; + Postfix postfix; + }; - struct confix_fn - { - template - static constexpr confix_gen, as_parser_plain_t> - operator()(Prefix&& prefix, Postfix&& postfix) - noexcept( - is_parser_nothrow_castable_v && - is_parser_nothrow_castable_v && - std::is_nothrow_constructible_v< - detail::confix_gen, as_parser_plain_t>, - as_parser_t, as_parser_t - > - ) - { - return { as_parser(std::forward(prefix)), as_parser(std::forward(postfix)) }; - } - }; - } // detail - inline namespace cpos + template + constexpr confix_gen::value_type, + typename extension::as_parser::value_type> + confix(Prefix const& prefix, Postfix const& postfix) { - inline constexpr detail::confix_fn confix{}; - } // cpos -} // boost::spirit::x3 + return { as_parser(prefix), as_parser(postfix) }; + } + +}}} #endif diff --git a/test/x3/confix.cpp b/test/x3/confix.cpp index bf2d81c18..259f723aa 100644 --- a/test/x3/confix.cpp +++ b/test/x3/confix.cpp @@ -1,14 +1,11 @@ /*============================================================================= Copyright (c) 2009 Chris Hoeppler Copyright (c) 2014 Lee Clagett - Copyright (c) 2025 Nana Sakisaka Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include "test.hpp" - #include #include #include @@ -16,6 +13,8 @@ #include #include +#include "test.hpp" + int main() { namespace x3 = boost::spirit::x3; @@ -26,7 +25,7 @@ int main() BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(x3::confix("/*", "*/")); { - constexpr auto comment = x3::confix("/*", "*/"); + const auto comment = x3::confix("/*", "*/"); BOOST_TEST(test_failure("/abcdef*/", comment["abcdef"])); BOOST_TEST(test_failure("/* abcdef*/", comment["abcdef"])); @@ -36,18 +35,18 @@ int main() { unsigned value = 0; BOOST_TEST( - test_attr(" /* 123 */ ", comment[x3::uint_], value, x3::standard::space)); + test_attr(" /* 123 */ ", comment[x3::uint_], value, x3::space)); BOOST_TEST(value == 123); using x3::_attr; value = 0; - auto const lambda = [&value](auto& ctx) { value = _attr(ctx) + 1; }; + const auto lambda = [&value](auto& ctx ){ value = _attr(ctx) + 1; }; BOOST_TEST(test_attr("/*123*/", comment[x3::uint_][lambda], value)); BOOST_TEST(value == 124); } } { - constexpr auto array = x3::confix('[', ']'); + const auto array = x3::confix('[', ']'); { std::vector values;