Closed yixing-liu closed 5 years ago
In your code, you expect that argument
can store data. However, argument
acts like a void *
with type information so that all elements in the args
point to the same variant v
. You can use vector<variant>
to store data and convert it to vector<argument>
when you need to invoke the function.
Thank you! I will close the issue then.
I observe some unexpected behavior with
argument
andvariant
. They seem more like a bug than a feature.Here are my code snippets. It compiles with GCC on a Linux box.
My expected output is
The actual output is
This seems rather weird to me. Does it have something to do with perfect forwarding or global reference? If I add this line
variant tmp = -1;
right belowvariant ret = type::invoke("sum4", args);
, then the output will beIt seems that all values in the vector of arguments
args
refer to the closest (most recent) value of variant type.Is this desired behavior?
How can I use invoke if I want to pass in multiple arguments that are only known at runtime? I know
type::invoke("sum", {1, 2, 3, 4})
will always work.