kiselgra / c-mera

Next-level syntax for C-like languages :)
Other
405 stars 17 forks source link

C++ for-each / range-based for loop #65

Closed kiselgra closed 7 years ago

kiselgra commented 7 years ago

C-Mera currently does not support range-based iteration syntax.

As this is purely a syntactic extension I'm not entirely sure if we should even support it. We can easily define a macro for those cases.

However, supporting it would increase our coverage of C++ and probably be forthcoming to new users...

@lispbub What do you think?

kiselgra commented 7 years ago

User-space macro could look like this:

(defmacro for-each ((name container &key (iterator (gensym "ITERATOR"))) &body body)
  `(for ((auto ,iterator = (funcall (oref ,container begin))) (!= ,iterator (funcall (oref ,container end))) (postfix++ ,iterator))
     (decl ((auto ,name = (dref ,iterator)))
       ,@body)))