Skip to content

Instantly share code, notes, and snippets.

View modelinheritance.d
struct ModelA {
class Animal {
TypeInfo eat() {
return typeid(typeof(this));
}
Food eatsFood() {
return null;
}
mixin fixCast!();
}
@Biotronic
Biotronic / 1 - Innledende post
Last active Jun 8, 2019
Global oppvarming, episode 3
View 1 - Innledende post
Jeg skulle så gjerne visst hva realitetene er!
(Tekst fra dette bildet: https://i.imgur.com/GKtdf5w.png)
KLIMASVINDELEN
1970-årene - Ny istid på vei!
1980-årene - Sur nedbør og skogsdød!
1990-årene - Ozonlaget forsvinner!
2000-årene - Global oppvarming!
@Biotronic
Biotronic / nullcoalesce.d
Last active Aug 27, 2018
Null-coalescing operator in D
View nullcoalesce.d
struct NullCoalesce {
static auto opBinaryRight(string op : "|", T)(T lhs) {
return NullCoalesceImpl!T(lhs);
}
}
alias NullCoalesce nil;
struct NullCoalesceImpl(T) {
T value;
View namedparams.d
import std.meta : staticIndexOf, AliasSeq, Alias, staticMap, ApplyRight, aliasSeqOf;
import std.traits : isImplicitlyConvertible, Parameters, ParameterDefaults, ParameterIdentifierTuple, isCallable, fullyQualifiedName, isSomeString;
import std.conv : text, to;
import std.range : iota, join;
import std.algorithm.searching : count, find;
import std.array : array, byPair;
/// Helper type for creating named parameters on the form args.foo = 42.
struct args {
static auto opDispatch(string name, T)(T arg) {
@Biotronic
Biotronic / customint.d
Created May 21, 2018
A custom int type supporting various signed number representations as well as different endiannesses
View customint.d
module customint;
import std.traits : Unsigned;
import std.algorithm : among;
import std.conv : to;
/// The representation used for an instance of CustomInt.
/// Details on how these work can be found on https://en.wikipedia.org/wiki/Signed_number_representations
enum Representation
{
@Biotronic
Biotronic / headmutable.md
Created Mar 12, 2018
Implicit Head-mutable Conversion for Temporaries
View headmutable.md

Implicit Head-mutable Conversion for Temporaries

Field Value
DIP: 1xxx
Review Count: 0
Author: Biotronic

Abstract

This document describes a method for implicitly converting const data structures to head-mutable when types are inferred for temporary variables. This already happens for built-in pointers and arrays, but user-defined types do not enjoy the same benefit. This document argues for a solution where the existing alias this feature is pressed into service to create temporaries with the desired head-mutability when the aliased value has the right type.

@Biotronic
Biotronic / properties.d
Last active Mar 14, 2018
Library-only properties in D
View properties.d
struct S {
int n;
mixin property!("field", "get => this.n", "set => this.n = set");
}
unittest {
import std.conv : to;
S s;
s.field = 3;
assert(s.field == 3);
@Biotronic
Biotronic / complexfunctions.d
Last active Feb 19, 2019
Missing math functions in std.complex
View complexfunctions.d
import std.complex;
import std.math : log, ceil, floor, round, sinh, cosh, trunc, sin, cos, acos, PI, E, copysign, isInfinity, isNaN,
// sgn needs to be renamed as std.math.sgn greedily accepts any type whatsoever and fails spectacularly when used with non-builtins.
fsgn = sgn;
import std.traits : isFloatingPoint;
// Formulas from
// http://scipp.ucsc.edu/~haber/archives/physics116A10/arc_10.pdf
// http://www.suitcaseofdreams.net/Inverse_Functions.htm
// http://www.suitcaseofdreams.net/inverse__hyperbolic_functions.htm
@Biotronic
Biotronic / packs.d
Last active Mar 3, 2019
Compile-time structs in D
View packs.d
module packs;
import std.meta;
import std.traits;
/*
* Named packs (compile-time structs, or compile-time tuples) in D.
*
* PackedAliasSeq was recently discussed[0] on the D forum. Turns out, an
* implementation already exists in std.meta, called Pack.
* While Pack enables the implementation of some interesting algorithms (StaticZip,
@Biotronic
Biotronic / Layout.d
Last active Mar 5, 2018
Suggested design for Layout!T
View Layout.d
module layout;
import std.meta;
import std.traits;
import packs;
/**
* Deconstructs a type into its primitive fields, recursing into sub-types.
*
* Params: