11 #include <boost/hana/type.hpp>
13 #include <lager/constant.hpp>
14 #include <lager/reader.hpp>
15 #include <lager/lenses/optional.hpp>
17 #include <zug/into.hpp>
18 #include <zug/tuplify.hpp>
19 #include <zug/transducer/each.hpp>
20 #include <zug/run.hpp>
27 [](
auto t) -> decltype(
29 std::declval<
typename decltype(t)::type>().push_back(std::declval<
typename decltype(t)::type::value_type>())) { });
32 [](
auto t) -> decltype(
34 std::declval<
typename decltype(t)::type>().insert(std::declval<
typename decltype(t)::type::value_type>())) { });
36 struct ImmerPushBackOrInsertT
38 template<
class Container,
class ...InputRanges>
39 auto operator()(Container container, InputRanges &&...ins) {
40 using ContT = std::decay_t<Container>;
41 if constexpr (
hasPushBack(boost::hana::type_c<ContT>)) {
42 return std::move(container)
43 .push_back(zug::tuplify(std::forward<InputRanges>(ins)...));
45 static_assert(
hasInsert(boost::hana::type_c<ContT>),
46 "Container must have either push_back() or insert() method");
47 return std::move(container)
48 .insert(zug::tuplify(std::forward<InputRanges>(ins)...));
60 constexpr
static auto hasTransientType = boost::hana::is_valid(
61 [](
auto t) -> boost::hana::type<
typename decltype(t)::type::transient_type::persistent_type> {});
63 template<
class Container,
class Func,
class ...InputRanges>
64 auto operator()(Container &&m, Func &&transducer, InputRanges &&...ins)
const {
65 using ContainerT = std::decay_t<Container>;
66 if constexpr (hasTransientType(boost::hana::type_c<ContainerT>)) {
67 using TransientT =
typename ContainerT::transient_type;
69 std::forward<TransientT>(m.transient()),
70 std::forward<Func>(transducer),
71 std::forward<InputRanges>(ins)...)
76 std::forward<Func>(transducer)
81 std::forward<InputRanges>(ins)...);
93 [](
auto t) -> boost::hana::type<
typename decltype(t)::type::transient_type> { });
96 template<
class ResultContainer,
class Func>
97 auto operator()(ResultContainer c, Func transducer) {
100 using ContT = std::decay_t<ResultContainer>;
104 return zug::into(c, transducer, m);
115 template<
class Cursor>
118 return std::forward<Cursor>(c).make();
121 template<
class Cursor>
124 return (~std::forward<Cursor>(c)).get();
129 zug::map([](
auto &&event) {
130 return std::forward<decltype(event)>(event).content();
136 [](
auto t) -> decltype((
void) std::declval<
typename decltype(t)::type>().get()) { });
139 template<
class T,
class V>
143 zug::map([key=std::forward<T>(key), def=std::forward<V>(defaultValue)](
auto &&j) -> std::decay_t<V> {
144 using JsonT = decltype(j);
145 using ValueT = std::decay_t<V>;
148 return j.get().contains(key)
149 ? std::forward<JsonT>(j).get().at(key).template get<ValueT>()
152 return j.contains(key)
153 ? std::forward<JsonT>(j).at(key).template get<ValueT>()
156 }
catch (
const std::exception &) {
166 template<
class B1,
class ...Bs>
167 constexpr
auto operator()(B1 &&b1, Bs &&...bs)
const {
168 return std::forward<B1>(b1)
169 && operator()(std::forward<Bs>(bs)...);
172 constexpr
auto operator()()
const {
181 template<
class B1,
class ...Bs>
182 constexpr
auto operator()(B1 &&b1, Bs &&...bs)
const {
183 return std::forward<B1>(b1)
184 || operator()(std::forward<Bs>(bs)...);
187 constexpr
auto operator()()
const {
195 template<
class Cursor,
class ...Cursors>
196 constexpr
auto allCursors(Cursor &&first, Cursors &&...cursors)
198 return lager::with(std::forward<Cursor>(first),
199 std::forward<Cursors>(cursors)...)
208 template<
class Cursor,
class ...Cursors>
209 constexpr
auto anyCursor(Cursor &&first, Cursors &&...cursors)
211 return lager::with(std::forward<Cursor>(first),
212 std::forward<Cursors>(cursors)...)
auto operator~(Cursor &&c)
Definition: cursorutil.hpp:116
auto operator+(Cursor &&c)
Definition: cursorutil.hpp:122
ImmerPushBackOrInsertT immerPushBackOrInsert
Definition: cursorutil.hpp:53
constexpr auto hasPushBack
Definition: cursorutil.hpp:26
constexpr AllTrueT allTrue
Definition: cursorutil.hpp:177
constexpr auto hasInsert
Definition: cursorutil.hpp:31
constexpr AnyTrueT anyTrue
Definition: cursorutil.hpp:192
auto looksLikeImmer
Definition: cursorutil.hpp:92
constexpr auto isJsonWrap
Definition: cursorutil.hpp:135
Definition: location.hpp:10
constexpr auto eventContent
Definition: cursorutil.hpp:128
constexpr auto anyCursor(Cursor &&first, Cursors &&...cursors)
Definition: cursorutil.hpp:209
constexpr auto allCursors(Cursor &&first, Cursors &&...cursors)
Definition: cursorutil.hpp:196
constexpr auto jsonAtOr(T &&key, V &&defaultValue)
Definition: cursorutil.hpp:140
detail::IntoImmerT intoImmer
Definition: cursorutil.hpp:88
detail::ContainerMapT containerMap
Definition: cursorutil.hpp:111