for loop elimination

前端 未结 1 732
-上瘾入骨i
-上瘾入骨i 2021-01-14 05:10

I\'d like to use the indices trick to eliminate for loops in my C++11 program (similar to forced -funroll-loops).

Here\'s an example:

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 05:53

    Try this ( http://liveworkspace.org/code/e65a81d0d3e9b17692713fd3e9d681f5 ):

    template struct indices {};
    
    template struct indices_gen
      : indices_gen
    {};
    
    template struct indices_gen : indices
    {};
    

    Working example: http://liveworkspace.org/code/3d0ba21cc637a61c3e63d2db002f87af

    Edit : Check Xeo's comment. Above example don't check if S < E, so it can go bad if you make a mistake. This (Xeo's code) will return a compiler error in such case: http://liveworkspace.org/code/81205e13334e89537bdc0b79b3ba56fc

    0 讨论(0)
提交回复
热议问题