WIP: draft command binding by lambda...
as it stands, this does not work, since lambdas are passed by-value, while function references can only be passed by explicit reference, otherwise they'll degrade to a function pointer. And std::function requires a plain function signature as type argument, not the type of a function pointer (which doesn't mean you can't construct a std::function from a FP, indeed there is an explicit overload for that).
This commit is contained in:
parent
e9948084fc
commit
afadc35eab
1 changed files with 22 additions and 4 deletions
|
|
@ -28,6 +28,7 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "proc/cmd.hpp"
|
||||
#include "proc/control/command-def.hpp"
|
||||
#include "lib/format-string.hpp"
|
||||
#include "lib/format-cout.hpp"
|
||||
//#include "lib/time/timevalue.hpp"
|
||||
//#include "lib/p.hpp"
|
||||
|
|
@ -52,6 +53,7 @@ namespace test {
|
|||
using std::string;
|
||||
using std::regex;
|
||||
using std::regex_replace;
|
||||
using util::_Fmt;
|
||||
|
||||
|
||||
|
||||
|
|
@ -136,6 +138,9 @@ namespace test {
|
|||
CHECK (def_empty == CommandSetup("to be or not to be"));
|
||||
CHECK (def_empty != CommandSetup("to pee or not to pee"));
|
||||
|
||||
//////////// does not compile -- copy assignment prohibited...
|
||||
// def_empty = def_1;
|
||||
|
||||
|
||||
// add actual definition closures...
|
||||
CommandSetup def_0{"test.CommandSetup.def_0"};
|
||||
|
|
@ -153,11 +158,24 @@ namespace test {
|
|||
.undoOperation (undoIt);
|
||||
};
|
||||
|
||||
CommandSetup def_2{"test.CommandSetup.def_2"};
|
||||
|
||||
//////////// does not compile -- copy assignment prohibited...
|
||||
// def_empty = def_1;
|
||||
CommandSetup def_2 = CommandSetup{"test.CommandSetup.def_2"}
|
||||
= [&](CommandDef def) // NOTE: we capture context by reference
|
||||
{
|
||||
def.operation ([&](uint cnt)
|
||||
{
|
||||
testString += pattern % cnt; // NOTE: capture the field 'pattern' of the enclosing class
|
||||
})
|
||||
.captureUndo ([](uint) -> string
|
||||
{
|
||||
return testString;
|
||||
})
|
||||
.undoOperation ([](uint, string oldVal)
|
||||
{
|
||||
testString = oldVal;
|
||||
});
|
||||
};
|
||||
}
|
||||
_Fmt pattern{" %d times."};
|
||||
|
||||
|
||||
/** @test actually issue the definitions captured as side-effect of the preceding test. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue