hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
reference_holder.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_REFERENCE_HOLDER_HPP
7 #define IROHA_REFERENCE_HOLDER_HPP
8 
9 #include <boost/variant.hpp>
10 
11 namespace shared_model {
12  namespace detail {
17  template <typename T>
19  private:
20  using VariantType = boost::variant<T, T &>;
21 
22  public:
23  template <typename V>
24  explicit ReferenceHolder(V &&value) : variant_(std::forward<V>(value)) {}
25 
26  using ReferenceType = typename std::add_lvalue_reference_t<T>;
27  using PointerType = typename std::add_pointer_t<T>;
28 
29  using ConstReferenceType = typename std::add_lvalue_reference_t<const T>;
30  using ConstPointerType = typename std::add_pointer_t<const T>;
31 
33  return *ptr();
34  }
35 
37  return ptr();
38  }
39 
41  return &boost::apply_visitor(
42  [](auto &value) -> decltype(auto) { return (value); }, variant_);
43  }
44 
46  return *ptr();
47  }
48 
50  return ptr();
51  }
52 
54  return &boost::apply_visitor(
55  [](const auto &value) -> decltype(auto) { return (value); },
56  variant_);
57  }
58 
59  private:
60  VariantType variant_;
61  };
62  } // namespace detail
63 } // namespace shared_model
64 
65 #endif // IROHA_REFERENCE_HOLDER_HPP
ReferenceHolder(V &&value)
Definition: reference_holder.hpp:24
ReferenceType operator*()
Definition: reference_holder.hpp:32
Definition: reference_holder.hpp:18
Definition: peer.hpp:48
ConstPointerType operator->() const
Definition: reference_holder.hpp:49
typename std::add_lvalue_reference_t< const iroha::protocol::Peer > ConstReferenceType
Definition: reference_holder.hpp:29
ConstPointerType ptr() const
Definition: reference_holder.hpp:53
PointerType ptr()
Definition: reference_holder.hpp:40
PointerType operator->()
Definition: reference_holder.hpp:36
ConstReferenceType operator*() const
Definition: reference_holder.hpp:45
typename std::add_pointer_t< iroha::protocol::Peer > PointerType
Definition: reference_holder.hpp:27
typename std::add_pointer_t< const iroha::protocol::Peer > ConstPointerType
Definition: reference_holder.hpp:30
typename std::add_lvalue_reference_t< iroha::protocol::Peer > ReferenceType
Definition: reference_holder.hpp:26
Definition: command_executor.hpp:12