This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written in the D programming language. | |
/** | |
This module includes helper functions to anotate unsafe operations as trusted operations. | |
See: http://dlang.org/function.html | |
Here is the list of unsafe operations described in the spec. | |
- No casting from a pointer type to any type other than void*. | |
- No casting from any non-pointer type to a pointer type. | |
- No modification of pointer values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rdmd | |
import std.conv; | |
import std.exception; | |
version(unittest) {} | |
else | |
void main() | |
{ | |
// Error: static assert "The error handler's return value(void) does not have a common type with the expression(int)." | |
int x = "x".to!int.ifThrown!ConvException((e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* memmove(void* dest_, const void* src_, size_t n) | |
{ | |
auto dest = (cast(byte*)dest_)[0..n]; | |
auto src = (cast(byte*)src_)[0..n]; | |
if (dest.ptr < src.ptr || (src.ptr < dest.ptr && src.ptr+n < dest.ptr)) | |
{ | |
// move forward order | |
foreach(i; 0..n) | |
{ | |
dest[i] = src[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto tap(alias fun, Range)(Range r) | |
{ | |
alias fun_ = unaryFun!fun; | |
struct ResultType | |
{ | |
this(Range r) { this.r = r; } | |
@property auto front() | |
{ | |
auto ret = r.front; | |
fun_(ret); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Another implementation of std.random.RandomCover | |
* | |
* Execution time for popFront (n: length): | |
* std.random: O(n) | |
* this : O(1) | |
* | |
* Memory consumption: | |
* std.random: O(n) | |
* this : O(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.traits; | |
/** | |
* Returns: InputRange which returns integer partitions of $(D_PARAM n) in lexicographic order. | |
* See_Also: ZS1 in "Fast Algorithms for Generating Integer Partitions" | |
*/ | |
@safe pure nothrow | |
auto integerPartitions(UInt)(UInt n) | |
if (isIntegral!UInt && isUnsigned!UInt) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Another implementation of std.algorithm.cartesianProduct | |
* See_Also: $(LINK2 http://d.puremagic.com/issues/show_bug.cgi?id=10693, Issue 10693) | |
*/ | |
@safe auto cartesianProduct(RR...)(RR Rs) | |
{ | |
return CartesionProduct!RR(Rs); | |
} | |
@safe struct CartesionProduct(RR...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rdmd | |
import std.stdio; | |
import std.random; | |
import std.range; | |
void main(string[] args) | |
{ | |
writeRandomCovered!Random(10); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rdmd | |
/** | |
* Library implementation of T& in C++ | |
* i.e. Its value can be modified | |
* but its address cannot be modified. | |
**/ | |
struct Ref(T) | |
{ | |
@system this(ref T ptr) pure nothrow |
NewerOlder