参数列表中的元组

tuple from argument list

我写了一个远程调用程序包装器.. 在服务器端我有一些人类可读的界面,例如:

template<typename TBase>
class LogicUnit : TBase
{
public:
  int getLenFromCalculate(
    double antenaForce, const std::string & duration) IMPLEMENTATION;

  float calcSomeAlse(
    int tableW, float integral) IMPLEMENTATION;
};

从客户端我想这样使用它:

#define IMPLEMENTATION TUPLE_FROM_ARGS
#include "logicUnit.h"
#undef 

LogicUnit<ClientNetwork> logicUnit;
logicUnit.connect("10.123.123.123", "8080");
logicUnit.getLenFromCalculate( 20.032, "faster" );

ClientNetwork中我有一个辅助函数:

template< typename ... Args >
bool send( const std::string & funcName, std::tuple<Args...> tuple );

还有我的问题 - 我可以在 TUPLE_FROM_ARGS-macros 中写什么?我想要如下内容:

define TUPLE_FROM_ARGS send( __FUNCTION__, std::make_tuple( ??????? ) );

或者我该如何用其他方式解决我的问题? 在这个图书馆 http://code.google.com/p/simple-rpc-cpp/ 使用脚本生成器创建实现代码。但是我想,是不是可以通过使用模板和宏来实现。

看起来您正在寻找可变参数宏:

#define TUPLE_FROM_ARGS( ... ) \
    send( __FUNCTION__, std::make_tuple( __VA_ARGS__ ) );

如果您不清楚自己真正需要什么,就很难给出好的建议。学习写好 SSCCE。无论如何,也许您正在寻找这个:

template< typename... Args >
int getLenFromCalculate( Args&&... args )
{
    send( __FUNCTION__, std::make_tuple( std::forward< Args >( args )... ) );
}

(在上面我真的不再需要宏了)

-- 继续我的问题--

我有 class 成员的定义:

class LogicUnit
{
public:
  RPC_FUNC_BEGIN
      int getLenFromCalculate(double antenaForce, const std::string & duration);
  RPC_FUNC_END
};

在客户端,它必须是一些实现,在服务器端,它必须是另一个实现。例如:

// LogicUnit_c.h
int LogicUnit::getLenFromCalculate( double _1, const std::string & _2 )
{
    return send(__COUNTER__, _1, _2);
}

// LogicUnit_s.h
int LogicUnit::getLenFromCalculate( double antenaForce, const std::string & duration )
{
   return (int)(duration.length() * antenaForce);
}

如果我有很多成员,我必须写下一个看起来像模板的代码:

int Foo::fooBar( double _1, int _2 ) { return send(__COUNTER__, _1, _2); }
void Foo::someQwe( double _1, int _2 ) { return send(__COUNTER__, _1, _2); }
int Foo::getParam( const std::string & _1 ) { return send(__COUNTER__, _1); }
void Foo::beNext( int _1, float _2, SMyStruct _3 ) { return send(__COUNTER__, _1, _2, _3); }

我需要 __PRETTY_FUNCTION__ 之类的东西: How to get function signature via preprocessor define written before it?