小编Alb*_*lby的帖子

具有相应参数的模板函数到元组类型的子集

我想写这个函数find:

multi_set<int, string, double, myType> m; //vector of tuples
m.insert(/*some data*/);
m.find<1,2>("something",2.123);
Run Code Online (Sandbox Code Playgroud)

要么

m.find<0,3>(1,instanceOfMyType);
m.find<1>("somethingelse");
Run Code Online (Sandbox Code Playgroud)

哪里find可以参数化对应于元组参数的任何子集.

我的代码到目前为止:

template <typename ... T>
class multi_set{
    typedef  tuple < T... > Tuple;
    vector<tuple<T...>> data = vector<tuple<T...>>();

public:
    void insert(T... t){
        data.push_back(tuple<T...>(t...));
    }


    template<size_t ... Pos>
    void find(???){
    // then I would like to use those params to search through data and 
    // return first matching item
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ tuples subset variadic-templates c++11

9
推荐指数
1
解决办法
412
查看次数

标签 统计

c++ ×1

c++11 ×1

subset ×1

tuples ×1

variadic-templates ×1