阅读背景:

C++11 —— 统计 tuple 中指定数据类型的数量

来源:互联网 

问题背景

  在实现可变参数列表中的类型统计功能前,我们先看看下面代码中的需求场景:

/**
 * @struct x_selector_t< size_t >
 * @brief  协助 make_task() 接口的特化选择功能的辅助类。
 */
template< size_t >
struct x_selector_t
{

};

/**
 * @brief xtuple 参数列表中未包含指定数据类型的时候,创建 x_task_A_t 对象。
 */
template< typename... _Args >
x_task_t * make_task(const x_selector_t< 0 > &, std::tuple< _Args... > && xtuple)
{
    using _Tuple = typename std::tuple< _Args... >;
    return (new x_task_A_t(std::forward< _Tuple >(xtuple)));
}

/**
 * @brief xtuple 参数列表中包含指定数据类型 1 个的时候,创建 x_task_B_t 对象。
 */
template< typename... _Args >
x_task_t * make_task(const x_selector_t< 1 > &, std::tuple< _Args... > && xtuple)
{
    using _Tuple = typename std::tuple< _Args... >;
    return (new x_task_B_t(std::forward< _Tuple >(xtuple)));
}

/**
 * @brief xtuple 参数列表中包含指定数据类型 2 个的时候,创建 x_task_C_t 对象。
 */
template< typename... _Args >
x_task_t * make_task(const x_selector_t< 2 > &, std::tuple< _Args... > && xtuple)
{
    using _Tuple = typename std::tuple< _Args... >;
    return (new x_task_C_t(std::forward< _Tuple >(xtuple)));
}
/



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: