Combining Bitsets

Say I have the following variables:

1
2
bitset <3> rank, file;
bitset<6> square;


Is there other way to assign the file bits to be the first 3 bits of square then the rank bits the last 3 other than

1
2
3
4
for (x = 0; x<=2; x++) {
square[x] =  file[x];
square[x+3] = rank[x];
} 


Thanks.
Last edited on
1
2
3
4
square.reset();
square |= rank;
square <<= 3;
square |= file;


Would that work?
Last edited on
You might be able to do an std::copy() or something, but honestly that is pretty simple.
@Zhuge that would not save processing time. I am looking for an optimized code.
@Daleth: I think so, that is very logical.
Last edited on
Ah, in that case then I'd guess either what you have or Daleth's suggestion. Try checking the assembly generated for each code snippet and see if either is obviously faster.
Topic archived. No new replies allowed.