4 #ifndef LEXY_CALLBACK_BIND_HPP_INCLUDED
5 #define LEXY_CALLBACK_BIND_HPP_INCLUDED
18 template <
typename BoundArg,
typename State,
typename... Args>
20 const _detail::
tuple<Args...>& actual_args)
23 return bound(state, actual_args);
34 template <std::size_t Idx,
typename Fn,
typename... BoundArgs,
typename State,
35 typename... ActualArgs, std::size_t... ActualIdx,
typename... ProducedArgs>
38 const _detail::
tuple<ActualArgs...>& actual_args,
40 ProducedArgs&&... produced_args)
42 if constexpr (Idx ==
sizeof...(BoundArgs))
52 = std::decay_t<
typename _detail::tuple<BoundArgs...>::template element_type<Idx>>;
53 if constexpr (std::is_same_v<bound_arg_t, all_values_placeholder>)
55 return _invoke_bound<Idx + 1>(
LEXY_FWD(fn), bound_args, state, actual_args,
56 actual_args.index_sequence(),
LEXY_FWD(produced_args)...,
58 LEXY_FWD(actual_args.template get<ActualIdx>())...);
62 return _invoke_bound<Idx + 1>(
LEXY_FWD(fn), bound_args, state, actual_args,
63 actual_args.index_sequence(),
LEXY_FWD(produced_args)...,
71 template <
typename Fn,
typename... BoundArgs, std::size_t... Idx,
typename State,
74 const _detail::
tuple<BoundArgs...>& bound_args,
76 State& state, Args&&... args)
79 if constexpr ((_detail::is_decayed_same<BoundArgs, _detail::all_values_placeholder> || ...))
82 return _invoke_bound<0>(
LEXY_FWD(fn), bound_args, state, actual_args,
83 actual_args.index_sequence());
106 template <
typename T,
typename = std::enable_if_t<std::is_default_constructible_v<T>>>
107 constexpr
operator T() const noexcept
113 template <std::
size_t N,
typename T,
typename Fn>
119 template <
typename State,
typename... Args>
121 const _detail::tuple<Args...>& args)
const
123 if constexpr (N >
sizeof...(Args))
127 using arg_t =
typename _detail::tuple<Args...>::template element_type<N - 1>;
128 if constexpr (_detail::is_decayed_same<arg_t, nullopt>)
135 template <std::
size_t N,
typename T>
140 template <
typename State,
typename... Args>
142 const _detail::tuple<Args...>& args)
const
144 if constexpr (N >
sizeof...(Args))
148 using arg_t =
typename _detail::tuple<Args...>::template element_type<N - 1>;
149 if constexpr (_detail::is_decayed_same<arg_t, nullopt>)
152 return args.template
get<N - 1>();
156 template <
typename Fn>
157 constexpr
auto map(Fn&& fn)
const
162 template <std::
size_t N,
typename Fn>
167 template <
typename State,
typename... Args>
169 const _detail::tuple<Args...>& args)
const
171 static_assert(N <=
sizeof...(Args),
"not enough arguments for nth_value<N>");
175 template <
typename Arg>
180 template <
typename Arg>
181 constexpr
auto or_(Arg&& fallback)
const
191 template <std::
size_t N>
195 static_assert(N > 0,
"values are 1-indexed");
197 template <
typename State,
typename... Args>
199 const _detail::tuple<Args...>& args)
const
201 static_assert(N <=
sizeof...(Args),
"not enough arguments for nth_value<N>");
202 return args.template
get<N - 1>();
205 template <
typename Arg>
210 template <
typename Arg>
211 constexpr
auto or_(Arg&& fallback)
const
221 template <
typename Fn>
222 constexpr
auto map(Fn&& fn)
const
229 template <std::
size_t N>
232 inline namespace placeholders
234 constexpr
auto _1 = nth_value<1>;
235 constexpr
auto _2 = nth_value<2>;
236 constexpr
auto _3 = nth_value<3>;
237 constexpr
auto _4 = nth_value<4>;
238 constexpr
auto _5 = nth_value<5>;
239 constexpr
auto _6 = nth_value<6>;
240 constexpr
auto _7 = nth_value<7>;
241 constexpr
auto _8 = nth_value<8>;
244 template <
typename Fn>
249 template <
typename State,
typename... Args>
250 constexpr decltype(
auto) operator()(State& state, const _detail::tuple<Args...>&)
const
252 static_assert(!std::is_same_v<State, _detail::no_bind_state>,
253 "lexy::parse_state requires that a state is passed to lexy::parse()");
260 template <
typename State,
typename... Args>
261 constexpr decltype(
auto) operator()(State& state, const _detail::tuple<Args...>&)
const
263 static_assert(!std::is_same_v<State, _detail::no_bind_state>,
264 "lexy::parse_state requires that a state is passed to lexy::parse()");
268 template <
typename Fn>
269 constexpr
auto map(Fn&& fn)
const
281 template <
typename Callback,
typename... BoundArgs>
289 template <
typename State>
295 template <
typename... Args>
304 template <
typename State>
310 template <
typename... Args>
320 template <
typename Callback,
typename... BoundArgs>
330 template <
typename Sink>
335 template <
typename... Args>
342 template <
typename Sink,
typename... BoundArgs>
348 template <
typename... Args>
354 template <
bool Dummy =
true,
355 typename =
std::enable_if_t<(!_detail::is_placeholder<BoundArgs> && ... && Dummy)>>
363 template <
typename State>
364 constexpr
auto sink(State& state)
const
374 template <
typename Sink,
typename... BoundArgs>
375 constexpr
auto bind_sink(Sink&& sink, BoundArgs&&... args)
378 (!_detail::is_decayed_same<BoundArgs, _detail::all_values_placeholder> && ...),
379 "lexy::values as a placeholder for bind_sink() doesn't make sense - there won't be any values");
385 #endif // LEXY_CALLBACK_BIND_HPP_INCLUDED