3

そこで、私は NSArrays をよく使用するので、ここにあるマクロに基づいて、渡されたプリミティブから配列を作成するマクロを作成することにしました。

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];
}

基本的に、私が求めているのは、可変引数マクロを使用して、マクロに渡された各引数に対して操作を実行するにはどうすればよいですか?

4

1 に答える 1

1

これはあなたの質問に対する直接的な回答ではありませんが、プリミティブのオートボクシング機能を含む LLVM 4.0 を待つべきでしょうか?

ご覧ください: http://blog.ablepear.com/2012/02/something-wonderful-new-objective-c.html

于 2012-03-03T16:25:20.293 に答える