Equivalent C++ to Python generator pattern

前端 未结 12 2369
Happy的楠姐
Happy的楠姐 2020-11-28 18:42

I\'ve got some example Python code that I need to mimic in C++. I do not require any specific solution (such as co-routine based yield solutions, although they would be acce

12条回答
  •  长情又很酷
    2020-11-28 19:14

    Something like this:

    Example use:

    using ull = unsigned long long;
    
    auto main() -> int {
        for (ull val : range_t(100)) {
            std::cout << val << std::endl;
        }
    
        return 0;
    }
    

    Will print the numbers from 0 to 99

提交回复
热议问题