This repository contains vczh's toys for black magic codes or experiments
This repository contains vczh's toys for black magic codes or experiments
This repository contains vczh's toys for black magic codes or experiments:
###./CppGarbageCollection ######// garbage collection library for C++
#include "gc_ptr.h"
using namespace vczh;
class Node : ENABLE_GC
{
public:
gc_ptr next;
};
int main()
{
gc_start(0x00100000, 0x00500000);
{
auto x = make_gc();
auto y = make_gc();
x->next = y;
y->next = x;
// static_gc_cast and dynamic_gc_cast is waiting for you who like doing pointer conversion
}
gc_force_collect(); // will search and delete x and y here
gc_stop(); // will call gc_force_collect()
}
###./CppMultiDimentionArray ######// multiple dimentional array for C++
#include "array.h"
using namespace vczh;
int main()
{
// int x[3][4][5]; but the lengths can be non-constant expressions
array x((array_sizes(), 3, 4, 5));
// first way to do x[1][2][3] = 10;
x[1][2][3] = 10;
// second way to do x[1][2][3] = 10;
array_ref x1 = x[1];
array_ref x2 = x1[2];
int& x3 = x2[3];
x3 = 10;
return 0;
}###./CppLinq ######// linq for C++11 and STL
#include "linq.h"
#include
using namespace std;
using namespace vczh;
int main()
{
{
// calculate sum of squares of odd numbers
int xs[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = from(xs)
.where([](int x){return x % 2 == 1; })
.select([](int x){return x * x; })
.sum();
// prints 165
cout >
cout
cout
using namespace std;
using namespace vczh;
int main()
{
auto fib = Y([](function fib, int i)
{
return i < 2 ? 1 : fib(i - 1) + fib(i - 2);
});
for (int i = 0; i < 10; i++)
{
cout << fib(i) << ' ';
}
cout << endl;
}No open issues yet, or sync has not completed.