Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ unpack/unbox class method arguments
    text
    copied!<p>I have a a bunch of subclasses each with static class factory methods of varying argument numbers and types, and would also like to instantiate them from data loaded via a json data file using <a href="http://jsoncpp.sourceforge.net/" rel="nofollow noreferrer">jsonpp</a>.</p> <p>So say I'll have an array of Json::Value objects for the arguments, is there a smart way, using macros or something in c++ to create alternate proxy methods that accepts the Json::Value array and calls the original method, e.g.)</p> <pre><code>Foo* Foo::create(int a, const char* b) { /* ... */ } Foo* Foo::create(Json::Value args) { //the Json::Value args represents an array value here // can I avoid having to manually create each of these Json methods? return Foo::create(args[0].asInt(), args[1].asCString()); } </code></pre> <p>Sorry, my c++ is still getting up to speed. I've found a few topics that seem to deal with unpacking tuple arguments for example,</p> <ul> <li><a href="https://stackoverflow.com/questions/10766112/c11-i-can-go-from-multiple-args-to-tuple-but-can-i-go-from-tuple-to-multiple?lq=1">C++11: I can go from multiple args to tuple, but can I go from tuple to multiple args?</a></li> <li><a href="https://stackoverflow.com/questions/687490/how-do-i-expand-a-tuple-into-variadic-template-functions-arguments">How do I expand a tuple into variadic template function&#39;s arguments?</a></li> <li><a href="https://stackoverflow.com/questions/11044504/any-solution-to-unpack-a-vector-to-function-arguments-in-c">Any Solution to Unpack a Vector to Function Arguments in C++?</a></li> </ul> <p>but I am unsure of which approach to proceed with. Thanks for the help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload