callback/base.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2023 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_CALLBACK_BASE_HPP_INCLUDED
5 #define LEXY_CALLBACK_BASE_HPP_INCLUDED
6 
10 
11 namespace lexy
12 {
13 template <typename T>
14 using _detect_callback = typename T::return_type;
15 template <typename T>
16 constexpr bool is_callback = _detail::is_detected<_detect_callback, T>;
17 
18 template <typename T, typename... Args>
19 using _detect_callback_for = decltype(LEXY_DECLVAL(const T)(LEXY_DECLVAL(Args)...));
20 template <typename T, typename... Args>
21 constexpr bool is_callback_for
22  = _detail::is_detected<_detect_callback_for, std::decay_t<T>, Args...>;
23 
24 template <typename T, typename State>
25 using _detect_callback_state = decltype(LEXY_DECLVAL(const T)[LEXY_DECLVAL(State&)]);
26 template <typename T, typename State>
27 constexpr bool is_callback_state
28  = _detail::is_detected<_detect_callback_state, T, std::decay_t<State>>;
29 
31 template <typename Sink, typename... Args>
32 using sink_callback = decltype(LEXY_DECLVAL(Sink).sink(LEXY_DECLVAL(Args)...));
33 
34 template <typename T, typename... Args>
35 using _detect_sink_callback_for = decltype(LEXY_DECLVAL(T&)(LEXY_DECLVAL(Args)...));
36 template <typename T, typename... Args>
37 constexpr bool is_sink_callback_for
38  = _detail::is_detected<_detect_sink_callback_for, std::decay_t<T>, Args...>;
39 
40 template <typename T, typename... Args>
41 using _detect_sink = decltype(LEXY_DECLVAL(const T).sink(LEXY_DECLVAL(Args)...).finish());
42 template <typename T, typename... Args>
43 constexpr bool is_sink = _detail::is_detected<_detect_sink, T, Args...>;
44 } // namespace lexy
45 
46 namespace lexy
47 {
48 template <typename Fn>
49 struct _fn_holder
50 {
51  Fn fn;
52 
53  constexpr explicit _fn_holder(Fn fn) : fn(fn) {}
54 
55  template <typename... Args>
56  constexpr auto operator()(Args&&... args) const
57  -> decltype(_detail::invoke(fn, LEXY_FWD(args)...))
58  {
59  return _detail::invoke(fn, LEXY_FWD(args)...);
60  }
61 };
62 
63 template <typename Fn>
64 using _fn_as_base = std::conditional_t<std::is_class_v<Fn>, Fn, _fn_holder<Fn>>;
65 
66 template <typename... Fns>
67 struct _overloaded : _fn_as_base<Fns>...
68 {
69  constexpr explicit _overloaded(Fns... fns) : _fn_as_base<Fns>(LEXY_MOV(fns))... {}
70 
71  using _fn_as_base<Fns>::operator()...;
72 };
73 
74 template <typename... Op>
75 constexpr auto _make_overloaded(Op&&... op)
76 {
77  if constexpr (sizeof...(Op) == 1)
78  return (LEXY_FWD(op), ...);
79  else
80  return _overloaded(LEXY_FWD(op)...);
81 }
82 } // namespace lexy
83 
84 #endif // LEXY_CALLBACK_BASE_HPP_INCLUDED
85 
detect.hpp
LEXY_MOV
#define LEXY_MOV(...)
Definition: config.hpp:21
lexy::_detail::is_detected
constexpr bool is_detected
Definition: detect.hpp:28
lexy::is_callback_for
constexpr bool is_callback_for
Definition: callback/base.hpp:22
lexy::_fn_holder
Definition: callback/base.hpp:49
lexy::sink_callback
decltype(LEXY_DECLVAL(Sink).sink(LEXY_DECLVAL(Args)...)) sink_callback
Returns the type of the .sink() function.
Definition: callback/base.hpp:32
config.hpp
lexy::_detect_sink_callback_for
decltype(LEXY_DECLVAL(T &)(LEXY_DECLVAL(Args)...)) _detect_sink_callback_for
Definition: callback/base.hpp:35
lexy::_detect_callback
typename T::return_type _detect_callback
Definition: callback/base.hpp:14
lexy::_detect_callback_state
decltype(LEXY_DECLVAL(const T)[LEXY_DECLVAL(State &)]) _detect_callback_state
Definition: callback/base.hpp:25
lexy::_fn_holder::fn
Fn fn
Definition: callback/base.hpp:51
lexy::_overloaded::_overloaded
constexpr _overloaded(Fns... fns)
Definition: callback/base.hpp:69
lexy::_overloaded
Definition: callback/base.hpp:67
lexy::is_callback_state
constexpr bool is_callback_state
Definition: callback/base.hpp:28
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:22
lexy
Definition: any_ref.hpp:12
lexy::is_callback
constexpr bool is_callback
Definition: callback/base.hpp:16
lexy::is_sink
constexpr bool is_sink
Definition: callback/base.hpp:43
lexy::_fn_holder::_fn_holder
constexpr _fn_holder(Fn fn)
Definition: callback/base.hpp:53
invoke.hpp
lexy::_detail::invoke
constexpr auto invoke(F ClassT::*f, Args &&... args) -> decltype(_mem_invoker< F ClassT::* >::invoke(f, LEXY_FWD(args)...))
Definition: invoke.hpp:56
lexy::op
typename LEXY_DECAY_DECLTYPE(Operator)::op_tag_type op
Definition: operator.hpp:41
lexy::_fn_holder::operator()
constexpr auto operator()(Args &&... args) const -> decltype(_detail::invoke(fn, LEXY_FWD(args)...))
Definition: callback/base.hpp:56
lexy::is_sink_callback_for
constexpr bool is_sink_callback_for
Definition: callback/base.hpp:38
lexy::_make_overloaded
constexpr auto _make_overloaded(Op &&... op)
Definition: callback/base.hpp:75
lexy::_detect_callback_for
decltype(LEXY_DECLVAL(const T)(LEXY_DECLVAL(Args)...)) _detect_callback_for
Definition: callback/base.hpp:19
LEXY_DECLVAL
#define LEXY_DECLVAL(...)
Definition: config.hpp:24
lexy::_detect_sink
decltype(LEXY_DECLVAL(const T).sink(LEXY_DECLVAL(Args)...).finish()) _detect_sink
Definition: callback/base.hpp:41
lexy::_fn_as_base
std::conditional_t< std::is_class_v< Fn >, Fn, _fn_holder< Fn > > _fn_as_base
Definition: callback/base.hpp:64


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:07