Template-ing a 'for' loop in C++?

后端 未结 10 673
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 12:58

I have a C++ snippet below with a run-time for loop,

for(int i = 0; i < I; i++)
  for (int j = 0; j < J; j++)
    A( row(i,j), column(i,j)         


        
10条回答
  •  臣服心动
    2020-12-25 13:29

    I would say it is a false good-idea.

    In C++ this : row::value
    means you will have as many differents row<>() functions than you have i * j. You don't want this because it will increase the size of the code and do a lot of instruction cache misses.

    I observed this when I was doing template functions to avoid a single boolean check.

    If is a short function just inline it.

提交回复
热议问题