This source file includes following definitions.
- list_create
- list_maybe_insert
- main
#include "Halide.h"
#include <stdio.h>
#include <list>
using namespace Halide;
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
extern "C" DLLEXPORT std::list<int> *list_create(int) {
return new std::list<int>();
}
HalideExtern_1(std::list<int> *, list_create, int);
extern "C" DLLEXPORT std::list<int> *list_maybe_insert(std::list<int> *list, bool insert, int value) {
if (insert) {
list->push_back(value);
}
return list;
}
HalideExtern_3(std::list<int> *, list_maybe_insert, std::list<int> *, bool, int);
int main(int argc, char **argv) {
Func factors;
Var x;
RDom r(1, 99);
factors(x) = list_create(x);
factors(x) = list_maybe_insert(factors(x), x%r == 0, r);
Buffer<std::list<int> *> result = factors.realize(100);
for (int i = 0; i < 100; i++) {
std::list<int> *list = result(i);
for (std::list<int>::iterator iter = list->begin(); iter != list->end(); iter++) {
int factor = *iter;
if (i % factor) {
printf("Error: %d is not a factor of %d\n", factor, i);
return -1;
}
}
delete list;
}
printf("Success!\n");
return 0;
}