C++11 range-based for loops without loop variable

前端 未结 10 1183
轮回少年
轮回少年 2020-12-24 04:33

In C++ I need to iterate a certain number of times, but I don\'t need an iteration variable. For example:

for( int x=0; x<10; ++x ) {
    /* code goes her         


        
10条回答
  •  滥情空心
    2020-12-24 05:07

    To join the contest:

    #include 
    #include 
    using namespace std;
    using namespace boost;
    
    namespace {
        template inline void 
        unused(const T&) {}
    }
    
    int main() {
        for (auto&& i : irange(0,10)) {
            unused(i);
            cout << "Something" << endl;
        }
        return 0;
    }
    

提交回复
热议问题