c++ - 将 boost::parameter_types 转换为 std::tuple
问题描述
我相信有一些方法可以用 MPL 和融合来做到这一点,但由于我是新手,所以很难弄清楚。
元组是std还是boost都没有关系,我最终要实现的是:
template<T>
void some_func()
{
// declare a tuple contains types of which in boost::function_types::parameter_types<T>
// insert values to the tuple
// call std::apply()
}
我尝试过使用 fold,但未能弄清楚第三个模板参数中应该包含什么。
解决方案
尚未对其进行测试,但以下应该可以工作:
#include <type_traits>
#include <tuple>
#include <boost/mpl/at.hpp> // For at
namespace detail {
template<class ParamSequence, std::size_t ...Indices>
auto unpack_params(ParamSequence, std::index_sequence<Indices...>) -> std::tuple<boost::mpl::at<ParamSequence, Indices>...>;
}
template<class Function>
using param_tuple_t = decltype(detail::unpack_params(boost::function_types::parameter_types<Function>(), std::make_index_sequence<boost::function_types::function_arity<Function>::value>()>()));
推荐阅读
- microsoft-graph-api - 收到 callRecord 通知后从 SharePoint 获取媒体文件
- r - 所有成绩单的线性回归
- javascript - 在 JavaScript 中将嵌套数组拆分为多个数组
- python-3.x - 将图像写入 PDF 文件
- javascript - 改进对 Openweathermap 的 API 调用以获取 Leaflet 上的图块
- vue.js - 如何在第二个 div 中重用第一个模板
- php - 如何查询 Solr apache php 数组一个值
- javascript - Javascript:从 src url 的 img 标签下载图像仅支持一次请求并被 crossOrigin 污染
- swift - 如何在 Swift 中更改 Core Data 的并发类型
- c# - 我没有按回车键,但 ReadLine() 说我做到了(不小心让你无法回答旧的,所以重新发布)