, (?) ?
, , - " , ?" ( , ?)
API:
class Generic
{
explicit Generic(std::function<float(float)> specialFunc);
};
Generic, . , specialFunc, ( " " , , ( " x, x" ), - , - ).
, specialFunc (.. specialFunc, , specialFunc, ..), .
. (, Generic , , final ).
( ) specialFunc , , - - .. - - , , .
TL;DR. , .
: beter (, , ) ... specialFunc " ":
:
class Generic
{
public:
Generic(std::function<float(float> f) : specialFunc{f} {}
void fancy_computation2() { 2 * specialFunc(2.); }
void fancy_computation4() { 4 * specialFunc(4.); }
private:
std::function<float(float> specialFunc;
};
:
class Generic
{
public:
Generic() {}
void fancy_computation2(std::function<float(float> f) { 2 * f(2.); }
void fancy_computation4(std::function<float(float> f) { 4 * f(4.); }
private:
};
( ) . , ( ).