Skip to content

Instantly share code, notes, and snippets.

/*
TWO ways: 1) dmd -c importer.d
2) dmd -c -unittest importer.d
*/
import importme; // *importme.d* is opened and semantic analysis on *importme.d* begins;
// now you should follow the comments from *importme.d*
//imports are solved now; semantic analysis continues
void main()
import mod;
struct Public {
int oops() {
return 42;
}
}
struct Nope {
@atilaneves
atilaneves / contract.d
Created January 9, 2019 15:29
Manual contract test
// This is only here to write a blog about it later
@("struct.onefield.int.manual")
@MockTU!(
{
import clang;
return MockCursor(
Cursor.Kind.TranslationUnit,
"",
MockType(),
[
@atilaneves
atilaneves / common.c
Last active November 8, 2018 14:29
int sort in C, C++, D
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#define SIZE (50 * 1000 * 1000)
int data[SIZE];
void init(int* data, int len) {
@atilaneves
atilaneves / betterc.d
Last active August 8, 2018 11:48
betterC classes
extern(C++) class Foo {
void stuff() {
import core.stdc.stdio;
printf("I'm foo!\n");
}
}
extern(C++) class Bar: Foo {
override void stuff() {
import core.stdc.stdio;
@atilaneves
atilaneves / cpp.cpp
Created April 6, 2018 16:38
C++ templates and D
template<typename T>
struct Foo {
T value;
T twice() const { return value * 2; }
};
#if __clang__
[[clang::optnone]]
#elif __GNUC__
@atilaneves
atilaneves / mod1.d
Created April 6, 2018 11:00
__traits(getUnitTests) with separate compilation
import std.stdio;
unittest {
writeln("mod1 test1");
}
unittest {
writeln("mod1 test2");
}
@atilaneves
atilaneves / interface_to_struct.d
Last active May 25, 2016 21:30
Create an object of a voldemort struct type that implements an interface
import std.traits;
template Identity(alias T) {
alias Identity = T;
}
template InterfaceToStruct(T) if(is(T == interface)) {
string mixinStr() {
@atilaneves
atilaneves / ctfoldl.d
Created February 26, 2016 17:22
Compile time left fold in D
import std.meta;
auto leftFold(alias F, alias T, Ts...)() {
auto leftFoldImpl(U, V, Vs...)(U accum, V value, Vs values) {
static if(values.length == 0)
return F(accum, value);
else
return leftFoldImpl(F(accum, value), values);
}
;;; init.el --- Atila Neves's custom emacs config
;; Copyright (C) 2013
;; Author: <aalvesne@cisco.com>
;; Keywords: init
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or