6 #ifndef IROHA_POSTGRES_WSV_COMMON_HPP 7 #define IROHA_POSTGRES_WSV_COMMON_HPP 10 #include <boost/optional.hpp> 11 #include <boost/range/adaptor/filtered.hpp> 12 #include <boost/range/adaptor/transformed.hpp> 13 #include <boost/range/iterator_range.hpp> 14 #include <boost/tuple/tuple.hpp> 20 template <
typename ParamType,
typename Function>
30 case soci::i_truncated:
38 constexpr std::size_t
length_v = boost::tuples::length<T>::value;
41 template <std::
size_t N,
typename T>
42 using element_t =
typename boost::tuples::element<N, T>::type;
45 template <
class Tuple1,
class Tuple2, std::size_t... Is, std::size_t... Js>
46 auto concat_impl(std::index_sequence<Is...>, std::index_sequence<Js...>)
47 -> boost::tuple<element_t<Is, std::decay_t<Tuple1>>...,
51 template <
class Tuple1,
class Tuple2>
52 using concat = decltype(concat_impl<Tuple1, Tuple2>(
53 std::make_index_sequence<length_v<std::decay_t<Tuple1>>>{},
54 std::make_index_sequence<length_v<std::decay_t<Tuple2>>>{}));
57 template <
typename F, std::size_t... Is>
59 std::index_sequence<Is...>) {
60 return std::forward<F>(f)(std::integral_constant<std::size_t, Is>{}...);
64 template <
size_t N,
typename F>
67 std::make_index_sequence<N>{});
71 template <
typename Tuple,
typename F>
72 constexpr decltype(
auto)
apply(Tuple &&t, F &&f) {
73 return index_apply<length_v<std::decay_t<Tuple>>>(
74 [&](
auto... Is) -> decltype(
auto) {
75 return std::forward<F>(f)(
76 boost::get<Is>(std::forward<Tuple>(t))...);
81 template <
typename R,
typename T>
83 return index_apply<length_v<std::decay_t<R>>>([&](
auto... Is) {
84 return boost::make_tuple(std::forward<T>(t).
template get<Is>()...);
89 template <
typename R,
typename T>
91 return index_apply<length_v<std::decay_t<R>>>([&](
auto... Is) {
92 return boost::make_tuple(
95 + length_v<std::decay_t<
96 T>> - length_v<std::decay_t<R>>>()...);
101 template <
typename T>
103 auto transform = [](
auto &&... vals) {
104 return boost::make_tuple(*std::forward<decltype(vals)>(vals)...);
107 using ReturnType = decltype(boost::make_optional(
112 [&](
auto &&... vals) {
113 bool temp[] = {
static_cast<bool>(
114 std::forward<decltype(vals)>(vals))...};
115 return std::all_of(std::begin(temp),
117 [](
auto b) {
return b; });
119 ? boost::make_optional(
124 template <
typename C,
typename T,
typename F>
126 return t | [&](
auto &st) -> boost::optional<C> {
127 return boost::copy_range<C>(
128 st | boost::adaptors::transformed([&](
auto &t) {
134 template <
typename C,
typename T,
typename F>
138 for (
auto &inp_el : *t) {
140 [&map_result](
auto &&transformed_el) {
141 map_result.emplace_back(std::move(transformed_el));
149 template <
typename R,
typename T,
typename F>
151 return t | [&](
auto &st) -> R {
152 auto range = boost::make_iterator_range(st);
165 #endif // IROHA_POSTGRES_WSV_COMMON_HPP
decltype(auto) constexpr apply(Tuple &&t, F &&f)
apply F to Tuple
Definition: soci_utils.hpp:72
decltype(auto) constexpr index_apply(F &&f)
apply F to an integer sequence [0, N)
Definition: soci_utils.hpp:65
auto mapValues(T &t, F &&f)
Definition: soci_utils.hpp:125
constexpr std::size_t length_v
tuple length shortcut
Definition: soci_utils.hpp:38
constexpr auto viewQuery(T &&t)
view first length_v<R> elements of T without copying
Definition: soci_utils.hpp:82
boost::optional< C > flatMapValues(T &t, F &&f)
Definition: soci_utils.hpp:135
Definition: block_query.hpp:15
decltype(auto) constexpr index_apply_impl(F &&f, std::index_sequence< Is... >)
index sequence helper for index_apply
Definition: soci_utils.hpp:58
auto concat_impl(std::index_sequence< Is... >, std::index_sequence< Js... >) -> boost::tuple< element_t< Is, std::decay_t< Tuple1 >>..., element_t< Js, std::decay_t< Tuple2 >>... >
index sequence helper for concat
constexpr auto rebind(T &&t)
map tuple<optional<Ts>...> to optional<tuple<Ts...>>
Definition: soci_utils.hpp:102
typename boost::tuples::element< N, T >::type element_t
tuple element type shortcut
Definition: soci_utils.hpp:42
void processSoci(soci::statement &st, soci::indicator &ind, ParamType &row, Function f)
Definition: soci_utils.hpp:21
decltype(concat_impl< Tuple1, Tuple2 >(std::make_index_sequence< length_v< std::decay_t< Tuple1 > >>{}, std::make_index_sequence< length_v< std::decay_t< Tuple2 > >>{})) concat
tuple with types from two given tuples
Definition: soci_utils.hpp:54
auto flatMapValue(T &t, F &&f)
Definition: soci_utils.hpp:150
constexpr auto viewPermissions(T &&t)
view last length_v<R> elements of T without copying
Definition: soci_utils.hpp:90