获取函数的第一个输入类型

时间:2017-08-22 08:43:13

标签: c++ templates c++17

我想推断出作为模板参数发送的函数的第一个输入参数。这样做可以让我删除参数inputtype,如果可以从下面的代码中的函数f推导出来的。{/ p>

template<typename inputtype, class  Fn, typename ...Params>
inline auto ListMap(const List* const polymorphic_list,
    Fn f,
    Params&&... params) {

    std::vector<decltype(f(nullptr, std::forward<Params>(params)...))> res;
    for (auto lcell = list_head(polymorphic_list); lcell; lcell = lcell->next) {
        const auto v = lcell->data.ptr_value;
        const inputtype* in = static_cast<const inputtype*>(v);
        res.emplace_back(std::move(f(in, std::forward<Params>(params)...)));
    }
    return res;
}

1 个答案:

答案 0 :(得分:1)

我创建了以下示例,其中成功推导出inputtype模板参数。希望您能够将这个想法整合到您的代码中。

PGPASSWORD