Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
tuple.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/utility.hpp>
3#include <boost/preprocessor/repeat.hpp>
4#include <boost/preprocessor/repeat_from_to.hpp>
5#include <boost/preprocessor/repetition/enum_binary_params.hpp>
6#include <boost/preprocessor/repetition/enum_params.hpp>
7#include <boost/preprocessor/repetition/enum.hpp>
8#include <boost/preprocessor/facilities/empty.hpp>
9#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
10
11namespace fc {
12
55 template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(9, typename A, void)> struct tuple{};
56
57 template<>
58 struct tuple<> {
59 enum size_enum { size = 0 };
60 template<typename V>
61 void visit( V&& v)const{};
62 };
63 template<typename Functor>
64 auto call_fused( Functor f, const tuple<>& t ) -> decltype( f( ) ) {
65 return f();
66 }
67
68 inline tuple<> make_tuple(){ return tuple<>(); }
69
70 template<typename T>
71 struct is_tuple {
73 };
74
75 #define RREF_PARAMS(z,n,data) BOOST_PP_CAT(AA,n)&& BOOST_PP_CAT(p,n)
76 #define ILIST_PARAMS(z,n,data) BOOST_PP_CAT(a,n)( fc::forward<BOOST_PP_CAT(AA,n)>( BOOST_PP_CAT(p,n) ) )
77 #define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
78 #define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
79 #define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
80 #define DEDUCE_MEMBERS(z,n,data) typename fc::deduce<BOOST_PP_CAT(AA,n)>::type
81 #define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(p,n))
82 #define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
83 #define TUPLE(z,n,unused) \
84 template<BOOST_PP_ENUM_PARAMS( n, typename A)> \
85 struct tuple<BOOST_PP_ENUM_PARAMS(n,A)> { \
86 enum size_enum { size = n }; \
87 template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
88 explicit tuple( BOOST_PP_ENUM(n, RREF_PARAMS, unused ) )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS,unused){} \
89 tuple( const tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
90 tuple( tuple&& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
91 tuple(){}\
92 template<typename V>\
93 void visit( V&& v ) { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
94 template<typename V>\
95 void visit( V&& v )const { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
96 BOOST_PP_REPEAT(n,MEM_PARAMS,a) \
97 }; \
98 template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
99 tuple<BOOST_PP_ENUM_PARAMS(n,AA)> make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \
100 return tuple<BOOST_PP_ENUM_PARAMS(n,AA)>( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \
101 } \
102 template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
103 auto call_fused( Functor f, tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
104 -> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
105 return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
106 } \
107 template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
108 auto call_fused( Functor f, const tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
109 -> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
110 return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
111 } \
112 template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
113 struct is_tuple<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
114 typedef fc::true_type type; \
115 }; \
116 template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
117 struct deduce<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
118 typedef fc::tuple<BOOST_PP_ENUM( n, DEDUCE_MEMBERS,unused)> type; \
119 };
120
121 BOOST_PP_REPEAT_FROM_TO( 1, 5, TUPLE, unused )
122
123
124 #undef FORWARD_PARAMS
125 #undef DEDUCE_MEMBERS
126 #undef RREF_PARAMS
127 #undef LIST_MEMBERS_ON
128 #undef ILIST_PARAMS
129 #undef ILIST_PARAMS_COPY
130 #undef VISIT_PARAMS
131 #undef MEM_PARAMS
132 #undef TUPLE
133
134
135}
136
namespace sysio::chain
Definition authority.cpp:3
auto call_fused(Functor f, const tuple<> &t) -> decltype(f())
Definition tuple.hpp:64
tuple make_tuple()
Definition tuple.hpp:68
Definition test_zm.cpp:19
fc::false_type type
Definition tuple.hpp:72
void visit(V &&v) const
Definition tuple.hpp:61
#define TUPLE(z, n, unused)
Definition tuple.hpp:83