Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-boxing NSArray?

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?

like image 361
Richard J. Ross III Avatar asked Sep 24 '26 07:09

Richard J. Ross III


1 Answers

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

like image 140
wzs Avatar answered Sep 27 '26 05:09

wzs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!