3

So, I use NSArrays a lot, so I decided to attempt to create a macro that will create an array from primitives passed in, based on the macros here:

https://bitbucket.org/snej/myutilities/src/319441e240fa/CollectionUtils.h

#define $array(values...) ({ void *v[] = { values }; const char *encodings[] = { /* how do I get the @encode-ings for each? */ };  _boxArray(v, encodings, sizeof(values) / sizeof(void *))})

NSValue *_box(void *value, const char *encoding); // defined by CollectionUtils

NSArray *_boxArray(void **values, const char **encodings, int count)
{
    id objects[count];

    for (int i = 0; i < count; i++) {
        // how can I box all of the values that need boxing?
        objects[i] = _box(values[i], encodings[i]);
    }

    return [NSArray arrayWithObjects:objects count:count];
}

So basically, what I am asking, is how can I, with variadic macro, perform an operation on each of the arguments passed to the macro?

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201

1 Answers1

1

This is not a direct answer for your question, but... Maybe you should just wait for LLVM 4.0, which includes autoboxing feature for primitives?

Have a look: http://blog.ablepear.com/2012/02/something-wonderful-new-objective-c.html

wzs
  • 1,057
  • 9
  • 12
  • Interesting. However, I will not accept this answer, as it is not current yet. If no answer is given when LLVM 4.0 Comes out, I will accept this answer. – Richard J. Ross III Mar 03 '12 at 16:27
  • I don't see anything in there about autoboxing, just concise syntax for instantiating certain classes. Am I missing something or did you post the wrong link? – Chuck Mar 05 '12 at 01:25