小编Tra*_*Cpp的帖子

Combine multiple vectors (results of function) into one with template

I'd like to have a templated function taking in a vector<T> v and a function op, mapping T to vector<U> and would like to concatenate the results of applying f to every element vector of v to return a vector<U> = [ Elements of op(v[0]), Elements of op(v[1]) ...].

A working option I found was adding an example in the function to allow for template deduction:

template <typename Container>
Container& concat(Container& c1, Container const& c2) {
  c1.insert(end(c1), begin(c2), end(c2));
  return …
Run Code Online (Sandbox Code Playgroud)

c++ templates stdvector c++11

5
推荐指数
1
解决办法
158
查看次数

标签 统计

c++ ×1

c++11 ×1

stdvector ×1

templates ×1