2
0
mirror of https://github.com/boostorg/spirit.git synced 2026-01-19 04:42:11 +00:00

Merge pull request #824 from saki7/modernize-omit

Use concepts in `x3::omit`. It is now a CPO that inhibits ADL.
This commit is contained in:
Nana Sakisaka
2025-09-10 10:25:22 +09:00
committed by GitHub
2 changed files with 43 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
/*=============================================================================
Copyright (c) 2001-2014 Joel de Guzman
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)
@@ -10,42 +11,58 @@
#include <boost/spirit/home/x3/support/unused.hpp>
#include <boost/spirit/home/x3/core/parser.hpp>
namespace boost { namespace spirit { namespace x3
#include <iterator>
#include <type_traits>
#include <utility>
namespace boost::spirit::x3
{
///////////////////////////////////////////////////////////////////////////
// omit_directive forces the attribute of subject parser
// to be unused_type
///////////////////////////////////////////////////////////////////////////
// `omit_directive` forces the attribute of subject parser
// to be `unused_type`
template <typename Subject>
struct omit_directive : unary_parser<Subject, omit_directive<Subject>>
{
typedef unary_parser<Subject, omit_directive<Subject> > base_type;
typedef unused_type attribute_type;
static bool const has_attribute = false;
using base_type = unary_parser<Subject, omit_directive<Subject>>;
using attribute_type = unused_type;
using subject_type = Subject;
static constexpr bool has_attribute = false;
typedef Subject subject_type;
constexpr omit_directive(Subject const& subject)
: base_type(subject) {}
template <typename SubjectT>
requires std::is_constructible_v<Subject, SubjectT>
constexpr omit_directive(SubjectT&& subject)
noexcept(std::is_nothrow_constructible_v<Subject, SubjectT>)
: base_type(std::forward<SubjectT>(subject))
{}
template <typename Iterator, typename Context, typename RContext>
bool parse(Iterator& first, Iterator const& last
, Context const& context, RContext& rcontext, unused_type) const
template <std::forward_iterator It, std::sentinel_for<It> Se, typename Context, typename RContext>
[[nodiscard]] constexpr bool
parse(
It& first, Se const& last, Context const& context, RContext& rcontext, unused_type
) const noexcept(is_nothrow_parsable_v<Subject, It, Se, Context, RContext, unused_type>)
{
static_assert(Parsable<Subject, It, Se, Context, RContext, unused_type>);
return this->subject.parse(first, last, context, rcontext, unused);
}
};
struct omit_gen
namespace detail
{
template <typename Subject>
constexpr omit_directive<typename extension::as_parser<Subject>::value_type>
operator[](Subject const& subject) const
struct omit_gen
{
return { as_parser(subject) };
}
};
template <X3Subject Subject>
[[nodiscard]] constexpr omit_directive<as_parser_plain_t<Subject>>
operator[](Subject&& subject) const
noexcept(is_parser_nothrow_constructible_v<omit_directive<as_parser_plain_t<Subject>>, as_parser_t<Subject>>)
{
return { as_parser(std::forward<Subject>(subject)) };
}
};
} // detail
constexpr auto omit = omit_gen{};
}}}
inline namespace cpos
{
inline constexpr detail::omit_gen omit{};
}
} // boost::spirit::x3
#endif

View File

@@ -5,13 +5,14 @@
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 <boost/spirit/home/x3.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
#include <string>
#include <iostream>
#include "test.hpp"
using boost::spirit::x3::rule;
@@ -26,7 +27,7 @@ BOOST_SPIRIT_X3_DEFINE(indirect_rule)
int main()
{
using namespace boost::spirit::x3::ascii;
using namespace boost::spirit::x3::standard;
using boost::spirit::x3::omit;
using boost::spirit::x3::unused_type;
using boost::spirit::x3::unused;