summaryrefslogtreecommitdiffhomepage
path: root/include/stc/algo/crange.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/stc/algo/crange.h')
-rw-r--r--include/stc/algo/crange.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/include/stc/algo/crange.h b/include/stc/algo/crange.h
index ca06c258..03162a2d 100644
--- a/include/stc/algo/crange.h
+++ b/include/stc/algo/crange.h
@@ -25,7 +25,7 @@
#include <stc/algo/filter.h>
#include <stc/algo/crange.h>
-int main()
+int main(void)
{
crange r1 = crange_make(80, 90);
c_foreach (i, crange, r1)
@@ -34,7 +34,8 @@ int main()
// use a temporary crange object.
int a = 100, b = INT32_MAX;
- c_forfilter (i, crange, crange_obj(a, b, 8),
+ crange r2 = crange_make(a, b, 8);
+ c_forfilter (i, crange, r2,
c_flt_skip(i, 10) &&
c_flt_take(i, 3))
printf(" %lld", *i.ref);
@@ -44,10 +45,7 @@ int main()
#ifndef STC_CRANGE_H_INCLUDED
#define STC_CRANGE_H_INCLUDED
-#include <stc/ccommon.h>
-
-#define crange_obj(...) \
- (*(crange[]){crange_make(__VA_ARGS__)})
+#include "../ccommon.h"
typedef long long crange_value;
typedef struct { crange_value start, end, step, value; } crange;
@@ -63,10 +61,10 @@ STC_INLINE crange crange_make_3(crange_value start, crange_value stop, crange_va
STC_INLINE crange_iter crange_begin(crange* self)
{ self->value = self->start; crange_iter it = {&self->value, self->end, self->step}; return it; }
-STC_INLINE crange_iter crange_end(crange* self)
+STC_INLINE crange_iter crange_end(crange* self)
{ crange_iter it = {NULL}; return it; }
-STC_INLINE void crange_next(crange_iter* it)
+STC_INLINE void crange_next(crange_iter* it)
{ *it->ref += it->step; if ((it->step > 0) == (*it->ref > it->end)) it->ref = NULL; }
#endif