callback/base.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2024 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 
30 template <typename T, typename State, typename... Args>
32  = decltype(LEXY_DECLVAL(const T)[LEXY_DECLVAL(State&)](LEXY_DECLVAL(Args)...));
33 template <typename T, typename State, typename... Args>
34 constexpr bool is_callback_with_state_for
35  = _detail::is_detected<_detect_callback_with_state_for, std::decay_t<T>, State, Args...>;
36 
38 template <typename Sink, typename... Args>
39 using sink_callback = decltype(LEXY_DECLVAL(Sink).sink(LEXY_DECLVAL(Args)...));
40 
41 template <typename T, typename... Args>
42 using _detect_sink_callback_for = decltype(LEXY_DECLVAL(T&)(LEXY_DECLVAL(Args)...));
43 template <typename T, typename... Args>
44 constexpr bool is_sink_callback_for
45  = _detail::is_detected<_detect_sink_callback_for, std::decay_t<T>, Args...>;
46 
47 template <typename T, typename... Args>
48 using _detect_sink = decltype(LEXY_DECLVAL(const T).sink(LEXY_DECLVAL(Args)...).finish());
49 template <typename T, typename... Args>
50 constexpr bool is_sink = _detail::is_detected<_detect_sink, T, Args...>;
51 } // namespace lexy
52 
53 namespace lexy
54 {
55 template <typename Fn>
56 struct _fn_holder
57 {
58  Fn fn;
59 
60  constexpr explicit _fn_holder(Fn fn) : fn(fn) {}
61 
62  template <typename... Args>
63  constexpr auto operator()(Args&&... args) const
64  -> decltype(_detail::invoke(fn, LEXY_FWD(args)...))
65  {
66  return _detail::invoke(fn, LEXY_FWD(args)...);
67  }
68 };
69 
70 template <typename Fn>
71 using _fn_as_base = std::conditional_t<std::is_class_v<Fn>, Fn, _fn_holder<Fn>>;
72 
73 template <typename... Fns>
74 struct _overloaded : _fn_as_base<Fns>...
75 {
76  constexpr explicit _overloaded(Fns... fns) : _fn_as_base<Fns>(LEXY_MOV(fns))... {}
77 
78  using _fn_as_base<Fns>::operator()...;
79 };
80 
81 template <typename... Op>
82 constexpr auto _make_overloaded(Op&&... op)
83 {
84  if constexpr (sizeof...(Op) == 1)
85  return (LEXY_FWD(op), ...);
86  else
87  return _overloaded(LEXY_FWD(op)...);
88 }
89 } // namespace lexy
90 
91 #endif // LEXY_CALLBACK_BASE_HPP_INCLUDED
detect.hpp
LEXY_MOV
#define LEXY_MOV(...)
Definition: config.hpp:29
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:56
lexy::sink_callback
decltype(LEXY_DECLVAL(Sink).sink(LEXY_DECLVAL(Args)...)) sink_callback
Returns the type of the .sink() function.
Definition: callback/base.hpp:39
config.hpp
lexy::_detect_sink_callback_for
decltype(LEXY_DECLVAL(T &)(LEXY_DECLVAL(Args)...)) _detect_sink_callback_for
Definition: callback/base.hpp:42
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:58
lexy::_overloaded::_overloaded
constexpr _overloaded(Fns... fns)
Definition: callback/base.hpp:76
lexy::_overloaded
Definition: callback/base.hpp:74
lexy::is_callback_state
constexpr bool is_callback_state
Definition: callback/base.hpp:28
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:30
lexy::is_callback_with_state_for
constexpr bool is_callback_with_state_for
Definition: callback/base.hpp:35
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:50
lexy::_fn_holder::_fn_holder
constexpr _fn_holder(Fn fn)
Definition: callback/base.hpp:60
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:63
lexy::is_sink_callback_for
constexpr bool is_sink_callback_for
Definition: callback/base.hpp:45
lexy::_make_overloaded
constexpr auto _make_overloaded(Op &&... op)
Definition: callback/base.hpp:82
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:32
lexy::_detect_callback_with_state_for
decltype(LEXY_DECLVAL(const T)[LEXY_DECLVAL(State &)](LEXY_DECLVAL(Args)...)) _detect_callback_with_state_for
Definition: callback/base.hpp:32
lexy::_detect_sink
decltype(LEXY_DECLVAL(const T).sink(LEXY_DECLVAL(Args)...).finish()) _detect_sink
Definition: callback/base.hpp:48
lexy::_fn_as_base
std::conditional_t< std::is_class_v< Fn >, Fn, _fn_holder< Fn > > _fn_as_base
Definition: callback/base.hpp:71


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16