Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Created February 18, 2017 10:26
Show Gist options
  • Save yvan-sraka/c0732a46ecb053f839cdd59255618a74 to your computer and use it in GitHub Desktop.
Save yvan-sraka/c0732a46ecb053f839cdd59255618a74 to your computer and use it in GitHub Desktop.
#include "stdio.h"
//stop
void stop()
{
throw 42;
}
//operation
enum class operation
{
clear,
clone,
};
//apply
using apply=void (*)(void* in,const operation,void* out=nullptr);
//val
struct val
{
void* _pointer=nullptr;
apply _apply=nullptr;
//destructor
~val()
{
clear();
}
//clear
void clear()
{
if(empty())
return;
_apply(_pointer,operation::clear);
}
//clone
val clone()
{
if(empty())
return {};
void* out=nullptr;
_apply(_pointer,operation::clone,&out);
return {out,_apply};
}
//empty
bool empty()
{
return _pointer==nullptr;
}
};
//primitive apply
template <typename T> void primitive_apply(void* in,const operation,void* out)
{
const value=(T)in;
if(op==operation::clear)
{
}
if(op==operation::clone)
{
}
}
//lift primitive
template <typename T> val lift_primitive(const T value)
{
//const auto result=[value](const action)
const auto function=[](void* pointer,const action)
{
};
return {value,function};
}
//lift
val lift(const int value)
{
return lift_primitive(value);
}
//main
int main(int count,const char** arguments)
{
lift(42);
printf("%s\n","ok");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment