Generating Sequences

Save to:
Instapaper Pocket Readability

A virtual container.

Generating Sequences

By Anthony Williams

From the article:

I was having a discussion with my son over breakfast about C++ and Python, and he asked me if C++ had anything equivalent to Python's range() function for generating a sequence of integers. I had to tell him that no, the C++ standard library didn't supply such a function, but there were algorithms for generating sequences (std::generate and std::generate_n) into an existing container, and you could write something that would provide a "virtual" container that would supply a sequence as you iterated over it with range-for...

Add a Comment

Comments are closed.

Comments (1)

0 0

JF said on Mar 13, 2017 11:59 AM:

Eric Niebler's proposal N4560: C++ Extensions for Ranges, does that and much much more...

Also boost's Range library (which has been around for quite some time) has irange and counting_range types.