c++变长模板



template<typename... Args>
inline auto sort_tuple(const std::tuple<Args...>& tp) {
	if constexpr (sizeof...(Args) == 2) {
		auto [a, b] = tp;
		if constexpr (!std::is_same_v<decltype(a), ormpp_key> && !std::is_same_v<decltype(a), ormpp_auto_key>)
			return std::make_tuple(b, a);
		else
			return tp;
	}
	else {
		return tp;
	}
}



//类成员函数变长参数
template<typename ...Arg>
void DbConfigInfo::AddInsert(const std::tuple<Arg...>& tp)    
{
	
}


template<typename ...Arg>
inline void Inser(Arg && ...arg)
{
	int size = sizeof...(arg);  //求变长参数个数
	
	auto ito = std::make_tuple(std::forward<Arg>(arg)...);  //转化为tuple

	std::tuple<int, int, int, int> b = ito;    //赋值给某种特定类型
	
	sort_tuple(std::make_tuple(std::forward<Arg>(arg)...));  //利用完美转发传参

	//std::invoke(可调对象, tuple参数);   
	//std::apply(函数, tuple参数);   
	AddInsert(b);
}

template<typename ...Arguments>
std::string  ErrMsgConfig::FormatVargs(const int64_t Errnum, const int64_t ClientType, Arguments && ...args)
{
	std::string ErrMsg;
	std::string Error;
	try
	{
		boost::format Format(ErrMsg);
		int unroll[]{ 0, (Format % std::forward<Arguments>(args), 0)... };
		static_cast<void>(unroll);
		Error = boost::str(Format);
	}
}


@
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值