Boost logo

Boost :

From: Daniel Wesslén (daniel_at_[hidden])
Date: 2006-12-05 02:46:22

Michael Fawcett wrote:
> On 12/3/06, Daniel Wesslén <daniel_at_[hidden]> wrote:
>> Not all swizzlings are named, but if the one you happen to want is not
>> provided then it is easy to create:
>> const indexer<bits::index_swizzle<0,0,2,0> > xxzx;
>> const indexer<bits::index_swizzle<3,2,1,0> > wzyx;
>> vector<4> v1, v2(1,2,3,4);
>> v1 = v2[xxzx]; // v1 = (1,1,3,1)
>> v1[xxzx] = v2; // error - v1[xxzx] is not a lvalue due to aliasing
>> v1[wzyx] = v2; // v1 = (4,3,2,1)
> I really dislike that syntax. Feel free to make use of the swizzle
> code generation macros I posted in the Vault. They generate all
> possible combinations so users don't have to make instances of your
> index_swizzle classes. You would want to replace the SWIZZLE_BODY
> macro with your own. It simply takes in the next permutation as a
> sequence, e.g. (z)(w)(y).
> The only downside is that there will be no compile-time error in
> situations like your //error line from above.
> v1.xxzx() = v2; // compiles, but doesn't make too much sense

Fair enough. I much prefer my syntax to yours, but the main reason for
posting was simply to present another way to do it - both syntax and

Obviously I could also generate all indexing objects, but in my
experience (~3 years of using this library in computer graphics), xy and
xyz are the only swizzlings (if you can even call them that) that's seen
any significant use.

Daniel Wesslén

Boost list run by bdawes at, gregod at, cpdaniel at, john at