C++11y allows us to eliminate some boilerplate!
[invirt/third/libt4.git] / rpc / marshall_wrap.h
index 2e54e47..04f5268 100644 (file)
@@ -17,14 +17,6 @@ typedef std::function<rpc_protocol::status(unmarshall &&, marshall &)> handler;
 //
 // We implement an 'invoke' function for functions of the RPC handler
 // signature, i.e. int(R & r, const Args...)
-//
-// One thing we need in order to accomplish this is a way to cause the compiler
-// to specialize 'invoke' with a parameter pack containing a list of indices
-// for the elements of the tuple.  This will allow us to call the underlying
-// function with the exploded contents of the tuple.  The empty type
-// tuple_indices<size_t...> accomplishes this.  It will be passed in to
-// 'invoke' as a parameter which will be ignored, but its type will force the
-// compiler to specialize 'invoke' appropriately.
 
 // This class encapsulates the default response to runtime unmarshalling
 // failures.  The templated wrappers below may optionally use a different
@@ -43,7 +35,7 @@ struct VerifyOnFailure {
 
 template <class F, class R, class RV, class args_type, size_t... Indices>
 typename enable_if<!std::is_member_function_pointer<F>::value, RV>::type inline 
-invoke(RV, F f, void *, R & r, args_type & t, tuple_indices<Indices...>) {
+invoke(RV, F f, void *, R & r, args_type & t, std::index_sequence<Indices...>) {
     return f(r, std::get<Indices>(t)...);
 }
 
@@ -51,7 +43,7 @@ invoke(RV, F f, void *, R & r, args_type & t, tuple_indices<Indices...>) {
 
 template <class F, class C, class RV, class R, class args_type, size_t... Indices>
 typename enable_if<std::is_member_function_pointer<F>::value, RV>::type inline 
-invoke(RV, F f, C *c, R & r, args_type & t, tuple_indices<Indices...>) {
+invoke(RV, F f, C *c, R & r, args_type & t, std::index_sequence<Indices...>) {
     return (c->*f)(r, std::get<Indices>(t)...);
 }
 
@@ -88,10 +80,8 @@ struct marshalled_func_imp<F, C, RV(R &, Args...), ErrorHandler> {
             // Allocate space for the RPC response -- will be passed into the
             // function as an lvalue reference.
             R r;
-            // Perform the invocation.  Note that TUPLE_INDICES calls the
-            // default constructor of an empty struct with template parameters
-            // running from 0 up to (# args) - 1.
-            RV b = invoke(RV(), f, c, r, t, TUPLE_INDICES(Args));
+            // Perform the invocation.
+            RV b = invoke(RV(), f, c, r, t, std::index_sequence_for<Args...>{});
             // Marshall the response.
             m << r;
             // Make like a tree.