Skip to content

Instantly share code, notes, and snippets.

View pszturmaj's full-sized avatar

Piotr Szturmaj pszturmaj

  • Szczecin, Poland
View GitHub Profile
@pszturmaj
pszturmaj / dip44.txt
Created August 20, 2013 23:13
Unfinished DIP44
== Abstract ==
Introducing possible design of View types (aka refinement types) in D
== Rationale ==
Views (refinement types) are powerful way to express runtime invariants. They help with code deduplication and can simplify error handling. Also, they can enable certain optimizations.
== Description ==
Views are always declared as subtypes of other types, possibly other views:
ViewDeclaration:
@pszturmaj
pszturmaj / sdl.html
Created August 15, 2013 20:00
LDC2 + Emscripten + SDL + std.algorithms's sort & map
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
textarea.emscripten { font-family: monospace; width: 80%; }
div.emscripten { text-align: center; }
@pszturmaj
pszturmaj / sdl.d
Last active December 21, 2015 03:39
LDC2 + Emscripten + SDL + std.algorithms's sort & map
// this is modified example
// original is from: http://d.hatena.ne.jp/ABA/20130331#p1
import SDL;
import SDL_video;
import std.stdio;
import std.algorithm;
immutable width = 640, height = 480;
SDL_Surface *screen;
int ticks = 0;
@pszturmaj
pszturmaj / gist:1299046
Created October 19, 2011 17:34
Conversion between composite types
/**
Object-to-object conversion converts each field in turn. Possible conversions are
between tuples, structs and classes. Target class must have a default constructor.
*/
T toImpl(T, S)(S src)
if (!isImplicitlyConvertible!(S, T) &&
!is(typeof(T(src))) && !is(typeof(new T(src))) && // don't conflict with converting construction
!isAssociativeArray!T && !isAssociativeArray!S && // don't conflict with AA conversion
!is(typeof(S.init.opCast!T()) : T) && // don't conflict with opCast conversion
!is(T == union) && !is(S == union) && // unions not supported