4 #include <boost/any.hpp>
5 #include <boost/config.hpp>
10 # define FC_CALL_MEMBER_TEMPLATE_KEYWORD
12 # define FC_CALL_MEMBER_TEMPLATE_KEYWORD template
18 template<
typename T>
struct is_optional :
public std::false_type {};
23 template<
typename T,
typename... Ts>
struct all_optionals<T, Ts...> :
public std::false_type {};
34 template<
typename R,
typename... Parameters>
36 using std::function<R(Parameters...)>::operator();
38 template<
typename... CutList>
44 template<
unsigned RemoveCount,
typename... Types>
46 template<
unsigned RemoveCount,
typename,
typename... Types>
48 template<
typename... Types>
53 template<
unsigned RemoveCount,
typename T,
typename... Types>
56 template<
unsigned RemoveCount,
typename... Types>
58 template<
unsigned RemoveCount,
typename... Types>
61 template<
typename F,
typename... OptionalTypes>
63 return f(OptionalTypes()...);
68 template<
class... Args>
69 std::enable_if_t<
sizeof...(Args) <
sizeof...(Parameters), R> operator()(Args... args) {
71 auto partial_function = [
this, &args...](
auto&&... rest) {
72 return (*
this)(std::forward<decltype(args)>(args)..., std::move(rest)...);
75 pack_cutter_t<
sizeof...(Args), std::decay_t<Parameters>...> dummy;
95 template<
typename R,
typename C,
typename P,
typename... Args>
97 template<
typename R,
typename C,
typename P,
typename... Args>
101 template<
typename Interface,
typename Transform >
102 struct vtable :
public std::enable_shared_from_this<vtable<Interface,Transform>>
105 template<
typename OtherType>
111 template<
typename R,
typename MemberPtr,
typename... Args>
112 void operator()(
const char* name, std::function<R(Args...)>& memb, MemberPtr m )
const {
114 memb = [src,m]( Args... args ){
return (src->*m)(args...); };
119 template<
typename Interface,
typename Transform >
137 template<
typename T >
144 template<
typename Interface,
typename Transform =
identity_member_with_optionals >
152 template<
typename T >
156 _data = std::make_shared<boost::any>(p);
157 T& ptr = boost::any_cast<T&>(*
_data);
158 auto& pointed_at = *ptr;
159 typedef typename std::remove_reference<decltype(pointed_at)>::type source_vtable_type;
181 #include <boost/preprocessor/repeat.hpp>
182 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
183 #include <boost/preprocessor/repetition/enum_params.hpp>
184 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
185 #include <boost/preprocessor/facilities/empty.hpp>
186 #include <boost/preprocessor/seq/for_each.hpp>
187 #include <boost/preprocessor/stringize.hpp>
189 #define FC_API_VTABLE_DEFINE_MEMBER( r, data, elem ) \
190 decltype(Transform::functor( (data*)nullptr, &data::elem)) elem;
191 #define FC_API_VTABLE_DEFINE_VISIT_OTHER( r, data, elem ) \
192 { typedef typename Visitor::other_type OtherType; \
193 v( BOOST_PP_STRINGIZE(elem), elem, &OtherType::elem ); }
194 #define FC_API_VTABLE_DEFINE_VISIT( r, data, elem ) \
195 v( BOOST_PP_STRINGIZE(elem), elem );
197 #define FC_API( CLASS, METHODS ) \
199 template<typename Transform> \
200 struct vtable<CLASS,Transform> : public std::enable_shared_from_this<vtable<CLASS,Transform>> { \
201 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_MEMBER, CLASS, METHODS ) \
202 template<typename Visitor> \
203 void visit_other( Visitor&& v ){ \
204 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT_OTHER, CLASS, METHODS ) \
206 template<typename Visitor> \
207 void visit( Visitor&& v ){ \
208 BOOST_PP_SEQ_FOR_EACH( FC_API_VTABLE_DEFINE_VISIT, CLASS, METHODS ) \