I have the situation where I need to split a number of bitset blocks in half. Is there a way to merge the following two functions into something resembling the third? Having something like the third feels more right and general.
pair<bitset<32>, bitset<32> >
split_block_in_half(
bitset<64> block
){
bitset<block.size()> filter;
for(size_t i = 0; i < filter.size()/2; ++i){
filter.set(i);
}
return make_pair<bitset<block.size()/2>, bitset<block.size()/2> >(
bitset<block.size()/2>(((block ^ (filter << (block.size()/2))) >> (block.size()/2)).to_ulong()),
bitset<block.size()/2>((block ^ filter).to_ulong())
);
}
pair<bitset<28>, bitset<28> >
split_block_in_half(
bitset<56> block
){
bitset<block.size()> filter;
for(size_t i = 0; i < filter.size()/2; ++i){
filter.set(i);
}
return make_pair<bitset<block.size()/2>, bitset<block.size()/2> >(
bitset<block.size()/2>(((block ^ (filter << (block.size()/2))) >> (block.size()/2)).to_ulong()),
bitset<block.size()/2>((block ^ filter).to_ulong())
);
}
template<
typename N>
pair<bitset<N>, bitset<N> >
split_block_in_half(
bitset<2*N> block
){
bitset<block.size()> filter;
for(size_t i = 0; i < filter.size()/2; ++i){
filter.set(i);
}
return make_pair<bitset<block.size()/2>, bitset<block.size()/2> >(
bitset<block.size()/2>(((block ^ (filter << (block.size()/2))) >> (block.size()/2)).to_ulong()),
bitset<block.size()/2>((block ^ filter).to_ulong())
);
}
Is there a clever compile time way to merge the two separate functions above, or is this unsupported?
template <int N>