6 #ifndef KAGOME_SCALE_TIE_HPP 7 #define KAGOME_SCALE_TIE_HPP 11 #define SCALE_TIE(N) \ 12 static constexpr size_t scale_tie = N; \ 13 template <typename T> \ 14 bool operator==(const T &r) const { \ 15 using ThisT = std::decay_t<decltype(*this)>; \ 16 using ExtT = std::decay_t<T>; \ 18 std::is_same_v<ExtT, ThisT> || std::is_base_of_v<ThisT, ExtT>); \ 19 return ::scale::as_tie(*this, [&](auto l) { \ 20 return ::scale::as_tie(r, [&](auto r) { return l == r; }); \ 23 template <typename T> \ 24 bool operator!=(const T &r) const { \ 25 return !operator==(r); \ 29 class ScaleEncoderStream;
30 class ScaleDecoderStream;
35 size_t N = std::remove_reference_t<T>::scale_tie>
37 if constexpr (N == 1) {
39 return std::forward<F>(f)(std::tie(v0));
40 }
else if constexpr (N == 2) {
42 return std::forward<F>(f)(std::tie(v0, v1));
43 }
else if constexpr (N == 3) {
44 auto &[v0, v1, v2] = v;
45 return std::forward<F>(f)(std::tie(v0, v1, v2));
46 }
else if constexpr (N == 4) {
47 auto &[v0, v1, v2, v3] = v;
48 return std::forward<F>(f)(std::tie(v0, v1, v2, v3));
49 }
else if constexpr (N == 5) {
50 auto &[v0, v1, v2, v3, v4] = v;
51 return std::forward<F>(f)(std::tie(v0, v1, v2, v3, v4));
52 }
else if constexpr (N == 6) {
53 auto &[v0, v1, v2, v3, v4, v5] = v;
54 return std::forward<F>(f)(std::tie(v0, v1, v2, v3, v4, v5));
55 }
else if constexpr (N == 7) {
56 auto &[v0, v1, v2, v3, v4, v5, v6] = v;
57 return std::forward<F>(f)(std::tie(v0, v1, v2, v3, v4, v5, v6));
58 }
else if constexpr (N == 8) {
59 auto &[v0, v1, v2, v3, v4, v5, v6, v7] = v;
60 return std::forward<F>(f)(std::tie(v0, v1, v2, v3, v4, v5, v6, v7));
61 }
else if constexpr (N == 9) {
62 auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8] = v;
63 return std::forward<F>(f)(std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8));
64 }
else if constexpr (N == 10) {
65 auto &[v0, v1, v2, v3, v4, v5, v6, v7, v8, v9] = v;
66 return std::forward<F>(f)(
67 std::tie(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9));
70 static_assert(1 <= N && N <= 10);
74 template <
typename T,
size_t = T::scale_tie>
75 ScaleEncoderStream &
operator<<(ScaleEncoderStream &s,
const T &v) {
77 std::apply([&](
const auto &...v) { (..., (s << v)); }, v);
82 template <
typename T,
size_t = T::scale_tie>
83 ScaleDecoderStream &
operator>>(ScaleDecoderStream &s, T &v) {
85 std::apply([&](
auto &...v) { (..., (s >> v)); }, v);
91 #endif // KAGOME_SCALE_TIE_HPP scale::ScaleEncoderStream & operator<<(scale::ScaleEncoderStream &s, const libp2p::peer::PeerInfo &peer_info)
auto as_tie(T &&v, F &&f)
scale::ScaleDecoderStream & operator>>(scale::ScaleDecoderStream &s, libp2p::peer::PeerInfo &peer_info)