Created
July 26, 2017 01:33
-
-
Save justinmeiners/08b5638a0d10eec9d15f23c2ff71a0a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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