Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Preprocessor macro loop __VA_ARGS__ 1 vs 2+ arguments
    text
    copied!<p>I'm using the macros from this <a href="https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros">post</a> looping through my arguments. Everything works great! However, is there a way to combine these two <code>CCB_CREATE</code> and <code>CCB_CREATE_MORE</code>? </p> <p>I need to extract the first argument <code>object_type</code> to write additional code. The additional <code>object_type</code>s will be using the <code>FOR_EACH</code> loop to insert into the map. </p> <p>The compiler complaints when I only have one argument when using <code>CCB_CREATE_MORE(Type1)</code>. To fix that I made another macro to handle that <code>CCB_CREATE(Type1)</code>. Hoping to find a clever solution to combine these two into one elegant macro. Any ideas?</p> <pre><code>#define INSERT_LOADER_MAP(object_type) loader_map.insert(make_pair(#object_type, object_type##Loader::loader())) #define CCB_CREATE_MORE(object_type,...) \ static CCNode * create##object_type##Node() { \ std::map&lt;std::string, CCNodeLoader*&gt; loader_map; \ std::string classname = #object_type; \ FOR_EACH(INSERT_LOADER_MAP,object_type,__VA_ARGS__); \ return loadCCBFile((classname + ".ccbi").c_str(), loader_map); \ } #define CCB_CREATE(object_type) \ static CCNode * create##object_type##Node() { \ std::map&lt;std::string, CCNodeLoader*&gt; loader_map; \ std::string classname = #object_type; \ INSERT_LOADER_MAP(object_type); \ return loadCCBFile((classname + ".ccbi").c_str(), loader_map); \ } </code></pre>
 

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