c++ - 参数列表中的元组

标签 c++ c++11 variadic-templates

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

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 宏中写什么?我想要如下内容:

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 )... ) );
}

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

关于c++ - 参数列表中的元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29187948/

相关文章:

c++ - 回车多行

c++ - 关于结构的警告 C26495?

c++ - 如果跨线程共享变量,将变量标记为 volatile 有用吗?

c++ - 引用限定符和删除的成员方法

c++ - 使用空参数包函数参数调用初始化列表中的函数

c++ - 将非类型参数包分布在不同的模板参数包中

c++ - Qt 网页程序集 : configure kit

c++ - 什么是 move 语义?

c++ - tellp() 是否未在追加模式下定义?

c++ - 如何有条件地在具有相同签名的两个构造函数之间切换?