我不知道如何获得这样的东西
I wonder how to get something like this
1 write
copy(a,b,2,3)2然后get,
a[2]=b[2]; a[3]=b[3]; a[4]=b[4];我知道C #defines不能递归地使用所以我假设模板元程序已经就位。
I know that C #defines can't be used recursively to get that effect, so I suppose that template meta-programming is in place.
我知道有一个boost库,但我只想要简单技巧
I know there is a boost library for that, but I only want that "simple" trick, and boost is too "messy".
谢谢
推荐答案最直接的解决方案是写一个循环,其中已知开始值和结束值。
The most straight forward solution to this is to write a loop where the start and end values are known
for(int i = 2; i <= 4; i++) { a[i]=b[i]; }我认为这比任何类型的模板/运行时调用混合更好:编写的循环对编译器的优化器是完全清楚的,没有任何级别的函数调用,只是为了看看发生了什么。
I think this is better than any sort of template/runtime-call mixture: The loop as written is completely clear to the compilers' optimizer, and there are no levels of function calls to dig through just to see what's going on.
更多推荐
如何在C ++中使用模板展开一个短循环?
发布评论