Skip to content

Instantly share code, notes, and snippets.

@garyo
Created July 15, 2018 17:22
Show Gist options
  • Save garyo/438c47e48a7d1efddce068dd717aa1b5 to your computer and use it in GitHub Desktop.
Save garyo/438c47e48a7d1efddce068dd717aa1b5 to your computer and use it in GitHub Desktop.
#include <vector>
struct add1_op {
void operator()(const float x0, float& dst) const {
dst = x0 + 1;
}
};
template<class Op>
struct process_vec1 {
void operator()(const std::vector<float> src, std::vector<float> dst) const {
for (size_t i = 0; i < src.size(); i++) {
Op{}(src[i], dst[i]);
}
}
};
template<typename Processor>
void dispatch(const std::vector<float> src, std::vector<float> dst, int mode)
{
if (mode == 0)
Processor()(src, dst);
// ... other modes ...
}
void add1_vec(const std::vector<float> src, std::vector<float> dst, int mode)
{
dispatch<process_vec1<add1_op> >(src, dst, mode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment