You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
584 B

3 years ago
#include <sm/state.h>
#include <sm/gen.h>
3 years ago
3 years ago
#include <cstdio>
3 years ago
SM_GENERATOR(powers_of_two)
3 years ago
{
3 years ago
int* a = SM_VAR(1);
SM_BEGIN;
{
while( (*a) > 0 ) {
SM_YIELD_VALUE(*a);
(*a) <<= 1;
}
}
SM_END;
3 years ago
}
int main()
{
3 years ago
auto state = sm_new_state();
auto gen = sm_generate(&powers_of_two);
3 years ago
3 years ago
sm_output output;
int out_int;
while(sm_next(&gen, state, &output)) {
if(!sm_output_value(output, &out_int))
continue;
printf("Power of two: %d\n", out_int);
}
3 years ago
3 years ago
sm_free_output(&output);
3 years ago
3 years ago
sm_free_generator(gen);
sm_free_state(state);
3 years ago
3 years ago
return 0;
3 years ago
}