1 // Written in the D programming language. 2 /* 3 NYSL Version 0.9982 4 5 A. This software is "Everyone'sWare". It means: 6 Anybody who has this software can use it as if he/she is 7 the author. 8 9 A-1. Freeware. No fee is required. 10 A-2. You can freely redistribute this software. 11 A-3. You can freely modify this software. And the source 12 may be used in any software with no limitation. 13 A-4. When you release a modified version to public, you 14 must publish it with your name. 15 16 B. The author is not responsible for any kind of damages or loss 17 while using or misusing this software, which is distributed 18 "AS IS". No warranty of any kind is expressed or implied. 19 You use AT YOUR OWN RISK. 20 21 C. Copyrighted to Kazuki KOMATSU 22 23 D. Above three clauses are applied both to source and binary 24 form of this software. 25 */ 26 27 /** 28 このモジュールではstd.typecons.Tupleとは違った無名型を構築します。 29 */ 30 module carbon.nonametype; 31 32 33 auto refT(alias var)() @safe 34 { 35 static struct RefT 36 { 37 auto ref get() pure nothrow @safe @nogc @property { return a; } 38 alias get this; 39 } 40 41 return RefT(); 42 } 43 44 45 auto refP(T)(T* p) @safe 46 { 47 static struct RefP 48 { 49 auto ref get() pure nothrow @safe @nogc inout @property { return *_p; } 50 alias get this; 51 private T* _p; 52 } 53 54 return RefP(p); 55 } 56 57 58 auto scopeRef(string str = "system", T)(ref T v) 59 if(str == "system" || str == "trusted") 60 { 61 mixin(`return () @` ~ str ~ ` { return refP(&v); }();`); 62 } 63 64 65 @safe 66 unittest { 67 int a; 68 auto p = a.scopeRef!"trusted"; 69 assert(p == 0); 70 71 p = 12; 72 assert(a == 12); 73 74 auto q = p; 75 ++q; 76 assert(a == p && a == 13); 77 } 78 79 80 81 class AssumeImplemented(C) : C 82 { 83 import std.functional : forward; 84 85 this(T...)(auto ref T args) 86 { 87 super(forward!args); 88 } 89 }