Skip to content

Instantly share code, notes, and snippets.

@justinmeiners
Created July 26, 2017 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinmeiners/08b5638a0d10eec9d15f23c2ff71a0a4 to your computer and use it in GitHub Desktop.
Save justinmeiners/08b5638a0d10eec9d15f23c2ff71a0a4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
template <class T, class F>
struct double_decorator
{
F func;
double_decorator(F func) : func(func) {}
T operator()(T x)
{
return func(x) * T(2);
}
};
template <class T, class F>
double_decorator<T, F> decorate(F func)
{
return double_decorator<T, F>(func);
}
float root(float x)
{
return std::sqrtf(x);
}
int main(int argc, const char* argv[])
{
auto d = decorate<float>(root);
std::cout << d(4.0f) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment