Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
import std.traits, std.range; struct NullTerminatedString(T) if (isSomeChar!T) { T* ptr; @property bool empty() { return *ptr == 0; } @property T front() { return *ptr; } void popFront() { ++ptr; } @property auto save() { return this; } } alias NullTerminatedString!(const(char)) cstring; alias NullTerminatedString!(const(wchar)) cwstring; alias NullTerminatedString!(const(dchar)) cdstring; static assert(isForwardRange!cstring); static assert(isForwardRange!cwstring); static assert(isForwardRange!cdstring); // TEST: import std.stdio; cstring getCString() { string s = "abc"; return cstring(s.ptr); } void main() { writeln(getCString()); }
Result:
Success
/
Return code: 0
/
Compilation time:
0.751
seconds
/
Run time:
0.024
seconds
Application output:
abc
Username
Message
Add comment
Paste info
Author:
Guest
Views:
133
Private:
no
Expires:
Never
Uploaded:
01.10.12 16:08
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.060
Pointer size:
m64
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason