Skip to content

Instantly share code, notes, and snippets.

/*
lazy hotload: hot reload a single function file, depends on opend imports
kinda dumb, dont expect templates, changing headers or anything to work
pass relivtivepath filename without the `.d`
*/
import core.stdc.stdlib;
import core.sys.posix.dlfcn;
template mkytemp(T,T[] fakedata=null){//my favorate bug
alias mkytemp=typeof(fakedata[0]);
}
unittest{ //verifing the bug still exists
static assert(is(mkytemp!int==int));
static assert(is(mkytemp!float==int));// <- spooky
}
/*the ast is modified live, so the T[] is defined and doesnt get properly "unset",
null and typeof just glue to make it work nicely; the effect is in the header at the callsite
DO NOT REPORT
import std;
void printctfe(alias A)(string s=""){
if(__ctfe){
__ctfeWrite("ct:"~A.to!string~":"~s~"\n");
} else {
writeln("rt:",A,":",s);
}}
template counter(discrim...){
enum counter=cast(immutable(void)*)[0].ptr;
alias seq(T...)=T;
template groupby(alias F,A...){
template groupby(int I){
alias groupby=seq!();
static foreach(J,a;A){
static if(F(J)==I){
groupby=seq!(groupby,a);
}
}}
}
struct fatslice(T){
T[] data;
int key,keyback;
ref T opIndex(int i)=>data[i+key];
int length()=>keyback-key;
auto opSlice(int i,int j)=>typeof(this)(data,i+key,j+key);
int opDollar()=>keyback-key;
T[] simplify()=>data[key..keyback];
}
auto zipslice(A...)(A args){
import std;
enum string compiler="dmd -unittest -main -run ";
enum string printer="bat --color=always ";
void append(string file,string line){
exe("echo \""~line~"\" >> "~file);
}
void exe(string s)=>executeShell(s).output.writeln;
void delete_(string file,int linestart,int lineend){
auto source=File(file,"r").byLineCopy.array;
File sink=File(file~"temp","w");

Statement Unittest

Field Value
DIP: (number/id -- assigned by DIP Manager)
Author: monkyyy, [email protected]
Implementation: (links to implementation PR if any)
Status: Draft

Abstract

import std;
alias seq=AliasSeq;
template isrange(alias R,string s){
static if(__traits(compiles,mixin("isInputRange!(typeof(R."~s~"))"))){
enum isrange=mixin("isInputRange!(typeof(R."~s~"))");
} else {
enum isrange=false;
}}
template childranges(R){
alias store=seq!();
auto curryrecurse(alias F,int I=2,Args...)(Args args){
static if(Args.length>I){
static if(is(typeof(F(args[0..I]))==void)){
F(args[0..I]);
curryrecurse!(F,I)(args[I..$]);
} else {
return curryrecurse!(F,I)(F(args[0..I]),args[I..$]);
}} else {
return F(args);
}}
import std;
auto takeUntil(R)(R base,R other){
static struct Result{
R base;
R other;
alias base this;
bool empty()=>base==other;
}
return Result(base,other);
}