提问人:DipStax 提问时间:9/29/2023 更新时间:9/29/2023 访问量:68
如何为包含的每个对象构造一个只有一个元素的元组?
How to construct a tuple with only one element for every object contained?
问:
我有一个带有多个模板类的元组,其中只有类的模板会发生变化,例如:
template<template<class> class T, class ...Ts>
class TriggerMap;
template<template<class> class T, class ...Ts>
class TriggerMap<T, std::tuple<Ts...>>
{
public:
TriggerMap(ThreadPool &_tp) : m_map(_tp) {}
~TriggerMap() = default;
private:
using TriggerMapImp = typename tuple_apply_template<T, Ts...>::type;
TriggerMapImp m_tup;
};
跟:tuple_apply_template
template<class, class>
struct tuple_prepend;
template<class T, class ...Ts>
struct tuple_prepend<T, std::tuple<Ts...>>
{
using type = std::tuple<T, Ts...>;
};
template<template<class> class T, class ...Ts>
struct tuple_apply_template;
template<template<class> class T, class _T, class ...Ts>
struct tuple_apply_template<T, _T, Ts...>
{
using type = typename tuple_prepend<T<_T>, typename tuple_apply_template<T, Ts...>::type>::type;
};
template<template<class> class T, class _T>
struct tuple_apply_template<T, _T>
{
using type = std::tuple<T<_T>>;
};
我想用对象引用来构造我的对象,在这种情况下是对象,我怎样才能以有效的方式更改(实际上不起作用)的构造函数以进行运行时优化?ThreadPool
TriggerMap
答:
0赞
DipStax
9/29/2023
#1
为了编译构造函数,我将其更改为:
TriggerMap(ThreadPool &_tp) : m_map(T<Ts>(_tp)...) {}
评论
std
::reference_wrapper
。TriggerMapImp
似乎只是std::tuple<T<Ts>...>
tuple_apply_template
~TriggerMap() = default;