Skip to content

AVasK/CPP-Range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

C ranges

That cool range syntax from Python now in C

requires C 11

Remember when you wrote a simple range-for in Python and said: "Wow, why cannot C have this?"

  for i in range(start, end, step)

Well, now it can!

  for (auto i : range(start, end, step))
  // and, indeed, it has other forms as well:
  for (auto i : range(start, end)) // <=> range(start, end, step=1)
  for (auto i : range(end) // <=> range(end)

Gets optimized to plain built-in for loop

tested on:

> Apple clang version 12.0.0)

> x86-64 GCC 10.2 (asm in godbolt)

Link to godbolt to try it yourself:

https://godbolt.org/z/qxssch

About

That cool range syntax from Python now in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages