hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
obj_utils.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_COMMON_OBJ_UTILS_HPP
7 #define IROHA_COMMON_OBJ_UTILS_HPP
8 
9 #include <boost/optional.hpp>
10 
11 namespace iroha {
12 
21  template <typename C>
22  auto makeOptionalGet(C map) {
23  return [&map](auto key) -> boost::optional<typename C::mapped_type> {
24  auto it = map.find(key);
25  if (it != std::end(map)) {
26  return it->second;
27  }
28  return boost::none;
29  };
30  }
31 
49  template <typename T, typename... Args>
50  auto makeMethodInvoke(T &object, Args &&... args) {
51  return [&](auto f) { return (object.*f)(std::forward<Args>(args)...); };
52  }
53 
62  template <typename V, typename B>
63  auto assignObjectField(B object, V B::*member) {
64  return [=](auto value) mutable {
65  object.*member = value;
66  return boost::make_optional(object);
67  };
68  }
69 
79  template <template <typename C> class P, typename V, typename B>
80  auto assignObjectField(P<B> object, V B::*member) {
81  return [=](auto value) mutable {
82  (*object).*member = value;
83  return boost::make_optional(object);
84  };
85  }
86 } // namespace iroha
87 
88 #endif // IROHA_COMMON_OBJ_UTILS_HPP
auto makeMethodInvoke(T &object, Args &&...args)
Definition: obj_utils.hpp:50
Definition: block_query.hpp:16
auto assignObjectField(B object, V B::*member)
Definition: obj_utils.hpp:63
auto makeOptionalGet(C map)
Definition: obj_utils.hpp:22
const std::string end
Definition: logger.cpp:9