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);
}
}
@
c++变长模板
于 2021-09-27 09:10:19 首次发布