aggregate.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_AGGREGATE_HPP_INCLUDED
5 #define LEXY_CALLBACK_AGGREGATE_HPP_INCLUDED
6 
7 #include <lexy/callback/base.hpp>
8 #include <lexy/dsl/member.hpp>
9 
10 namespace lexy
11 {
12 struct nullopt;
13 
14 template <typename T>
16 {
17  using return_type = T;
18  static_assert(std::is_aggregate_v<return_type>);
19 
20  constexpr T operator()(lexy::nullopt&&) const
21  {
22  return {};
23  }
24  constexpr T operator()(T&& result) const
25  {
26  return LEXY_MOV(result);
27  }
28 
29  template <typename Fn, typename Value, typename... Tail>
30  constexpr T operator()(lexy::member<Fn>, Value&& value, Tail&&... tail) const
31  {
32  T result{};
33  Fn{}(result, LEXY_FWD(value));
34  return (*this)(LEXY_MOV(result), LEXY_FWD(tail)...);
35  }
36  template <typename Fn, typename Value, typename... Tail>
37  constexpr T operator()(T&& result, lexy::member<Fn>, Value&& value, Tail&&... tail) const
38  {
39  Fn{}(result, LEXY_FWD(value));
40  return (*this)(LEXY_MOV(result), LEXY_FWD(tail)...);
41  }
42 
43  struct _sink
44  {
45  T _result{};
46 
47  using return_type = T;
48 
49  template <typename Fn, typename Value>
50  constexpr void operator()(lexy::member<Fn>, Value&& value)
51  {
52  Fn()(_result, LEXY_FWD(value));
53  }
54 
55  constexpr auto&& finish() &&
56  {
57  return LEXY_MOV(_result);
58  }
59  };
60  constexpr auto sink() const
61  {
62  return _sink{};
63  }
64 };
65 
67 template <typename T>
68 constexpr auto as_aggregate = _as_aggregate<T>{};
69 } // namespace lexy
70 
71 #endif // LEXY_CALLBACK_AGGREGATE_HPP_INCLUDED
72 
LEXY_MOV
#define LEXY_MOV(...)
Definition: config.hpp:21
lexy::_as_aggregate::_sink
Definition: aggregate.hpp:43
lexy::_as_aggregate::_sink::finish
constexpr auto && finish() &&
Definition: aggregate.hpp:55
base.hpp
lexy::as_aggregate
constexpr auto as_aggregate
A callback with sink that creates an aggregate.
Definition: aggregate.hpp:68
lexy::_as_aggregate::sink
constexpr auto sink() const
Definition: aggregate.hpp:60
lexy::_as_aggregate::operator()
constexpr T operator()(lexy::member< Fn >, Value &&value, Tail &&... tail) const
Definition: aggregate.hpp:30
lexy::_as_aggregate::_sink::operator()
constexpr void operator()(lexy::member< Fn >, Value &&value)
Definition: aggregate.hpp:50
lexy::_as_aggregate::_sink::return_type
T return_type
Definition: aggregate.hpp:47
lexy::_as_aggregate
Definition: aggregate.hpp:15
lexy::nullopt
Definition: option.hpp:25
LEXY_FWD
#define LEXY_FWD(...)
Definition: config.hpp:22
lexy::_as_aggregate::operator()
constexpr T operator()(T &&result) const
Definition: aggregate.hpp:24
lexy
Definition: any_ref.hpp:12
lexy::_as_aggregate::operator()
constexpr T operator()(lexy::nullopt &&) const
Definition: aggregate.hpp:20
lexy::member
Definition: member.hpp:24
lexyd::nullopt
constexpr auto nullopt
Definition: option.hpp:50
member.hpp
lexy::_as_aggregate::operator()
constexpr T operator()(T &&result, lexy::member< Fn >, Value &&value, Tail &&... tail) const
Definition: aggregate.hpp:37
lexy::_as_aggregate::return_type
T return_type
Definition: aggregate.hpp:17
lexy::_as_aggregate::_sink::_result
T _result
Definition: aggregate.hpp:45


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