Google is showing me lots of SO posts on passing lambdas as arguments, but they all seem to be C++0x/C++11 based (e.g. Use a lambda as a parameter for a C++ function) and I understand this is an area that has improved in more recent C++ versions?
I want to pass what is effectively a very simple delegate return MyGlobals.GetX()
as a method variable - in my case MyGlobals
is a global object.
i.e. in pseudocode
//stores and/or calls the lambda
myObject.SetXGetter({return MyGlobals.GetX()});
MyObject::SetXGetter(lambda?)
{
this->mLambda = Lambda;
cout << mLambda();
}
Older C++ versions made this quite messy having to use STL wrappers and temporary types, so in C++17 and above, how neatly can it be done... what would SetGetter
look like and can it be called passing the lambda directly in?
(If there are different alternatives for even newer versions, please share)