mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
has_public_example: std.array
This commit is contained in:
parent
8180178986
commit
b6512b94f4
2 changed files with 88 additions and 2 deletions
|
@ -120,7 +120,7 @@ exception_check="-std.concurrency,-std.net.curl,-std.parallelism,-std.range,-std
|
||||||
; Checks for poor placement of function attributes
|
; Checks for poor placement of function attributes
|
||||||
function_attribute_check="-std.algorithm.iteration,-std.concurrency,-std.conv,-std.datetime.interval,-std.exception,-std.functional,-std.net.curl,-std.numeric,-std.parallelism,-std.random,-std.range,-std.range.primitives,-std.socket,-std.traits,-std.typecons,-std.uni"
|
function_attribute_check="-std.algorithm.iteration,-std.concurrency,-std.conv,-std.datetime.interval,-std.exception,-std.functional,-std.net.curl,-std.numeric,-std.parallelism,-std.random,-std.range,-std.range.primitives,-std.socket,-std.traits,-std.typecons,-std.uni"
|
||||||
; Check for public declarations without a documented unittest
|
; Check for public declarations without a documented unittest
|
||||||
has_public_example="-etc.c.curl,-etc.c.sqlite3,-etc.c.zlib,-std.array,-std.ascii,-std.base64,-std.bitmanip,-std.complex,-std.concurrency,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.demangle,-std.digest.digest,-std.digest.hmac,-std.digest.murmurhash,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.null_allocator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.filelogger,-std.experimental.logger.multilogger,-std.experimental.typecons,-std.file,-std.format,-std.getopt,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.mathspecial,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.ir,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.xml,-std.zip,-std.zlib"
|
has_public_example="-etc.c.curl,-etc.c.sqlite3,-etc.c.zlib,-std.ascii,-std.base64,-std.bitmanip,-std.complex,-std.concurrency,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.demangle,-std.digest.digest,-std.digest.hmac,-std.digest.murmurhash,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.null_allocator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.logger.filelogger,-std.experimental.logger.multilogger,-std.experimental.typecons,-std.file,-std.format,-std.getopt,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.mathspecial,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.ir,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.xml,-std.zip,-std.zlib"
|
||||||
; Check for sortedness of imports
|
; Check for sortedness of imports
|
||||||
imports_sortedness="+disabled"
|
imports_sortedness="+disabled"
|
||||||
;imports_sortedness="-etc.c.curl,-std.algorithm.comparison,-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.c.freebsd.socket,-std.c.linux.pthread,-std.c.process,-std.complex,-std.concurrency,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.systime,-std.datetime.timezone,-std.digest.digest,-std.digest.hmac,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.common,-std.experimental.allocator.mallocator,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.math.biguintcore,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.utf,-std.uuid,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip"
|
;imports_sortedness="-etc.c.curl,-std.algorithm.comparison,-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.c.freebsd.socket,-std.c.linux.pthread,-std.c.process,-std.complex,-std.concurrency,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.container.util,-std.conv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.systime,-std.datetime.timezone,-std.digest.digest,-std.digest.hmac,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.common,-std.experimental.allocator.mallocator,-std.experimental.allocator.mmap_allocator,-std.experimental.allocator.showcase,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.math.biguintcore,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.net.isemail,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.utf,-std.uuid,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip"
|
||||||
|
|
88
std/array.d
88
std/array.d
|
@ -212,6 +212,18 @@ if (isNarrowString!String)
|
||||||
return cast(typeof(return)) str.toUTF32;
|
return cast(typeof(return)) str.toUTF32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
import std.range.primitives : isRandomAccessRange;
|
||||||
|
|
||||||
|
assert("Hello D".array == "Hello D"d);
|
||||||
|
static assert(isRandomAccessRange!string == false);
|
||||||
|
|
||||||
|
assert("Hello D"w.array == "Hello D"d);
|
||||||
|
static assert(isRandomAccessRange!dstring == true);
|
||||||
|
}
|
||||||
|
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
// @system due to array!string
|
// @system due to array!string
|
||||||
|
@ -534,7 +546,7 @@ if (isDynamicArray!T && allSatisfy!(isIntegral, I) && hasIndirections!(ElementEn
|
||||||
return arrayAllocImpl!(false, T, ST)(sizes);
|
return arrayAllocImpl!(false, T, ST)(sizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
/// ditto
|
||||||
auto uninitializedArray(T, I...)(I sizes) nothrow @trusted
|
auto uninitializedArray(T, I...)(I sizes) nothrow @trusted
|
||||||
if (isDynamicArray!T && allSatisfy!(isIntegral, I) && !hasIndirections!(ElementEncodingType!T))
|
if (isDynamicArray!T && allSatisfy!(isIntegral, I) && !hasIndirections!(ElementEncodingType!T))
|
||||||
{
|
{
|
||||||
|
@ -588,6 +600,18 @@ if (isDynamicArray!T && allSatisfy!(isIntegral, I))
|
||||||
return arrayAllocImpl!(true, T, ST)(sizes);
|
return arrayAllocImpl!(true, T, ST)(sizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe pure nothrow unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison : equal;
|
||||||
|
import std.range : repeat;
|
||||||
|
|
||||||
|
auto arr = minimallyInitializedArray!(int[])(42);
|
||||||
|
assert(arr.length == 42);
|
||||||
|
// Elements aren't necessarily initialized to 0
|
||||||
|
assert(!arr.equal(0.repeat(42)));
|
||||||
|
}
|
||||||
|
|
||||||
@safe pure nothrow unittest
|
@safe pure nothrow unittest
|
||||||
{
|
{
|
||||||
cast(void) minimallyInitializedArray!(int[][][][][])();
|
cast(void) minimallyInitializedArray!(int[][][][][])();
|
||||||
|
@ -1535,6 +1559,15 @@ if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(range.front))))
|
||||||
return range.splitter!isTerminator.array;
|
return range.splitter!isTerminator.array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
import std.uni : isWhite;
|
||||||
|
assert("Learning,D,is,fun".split(",") == ["Learning", "D", "is", "fun"]);
|
||||||
|
assert("Learning D is fun".split!isWhite == ["Learning", "D", "is", "fun"]);
|
||||||
|
assert("Learning D is fun".split(" D ") == ["Learning", "is fun"]);
|
||||||
|
}
|
||||||
|
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.algorithm.comparison : cmp;
|
import std.algorithm.comparison : cmp;
|
||||||
|
@ -3212,6 +3245,23 @@ if (isDynamicArray!A)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@system pure nothrow
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
int[] a = [1, 2];
|
||||||
|
auto app2 = appender(&a);
|
||||||
|
assert(app2.data == [1, 2]);
|
||||||
|
assert(a == [1, 2]);
|
||||||
|
app2 ~= 3;
|
||||||
|
app2 ~= [4, 5, 6];
|
||||||
|
assert(app2.data == [1, 2, 3, 4, 5, 6]);
|
||||||
|
assert(a == [1, 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
|
app2.reserve(5);
|
||||||
|
assert(app2.capacity >= 5);
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Convenience function that returns an $(LREF Appender) instance,
|
Convenience function that returns an $(LREF Appender) instance,
|
||||||
optionally initialized with $(D array).
|
optionally initialized with $(D array).
|
||||||
|
@ -3334,6 +3384,25 @@ Appender!(E[]) appender(A : E[], E)(auto ref A array)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe pure nothrow
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
auto w = appender!string;
|
||||||
|
// pre-allocate space for at least 10 elements (this avoids costly reallocations)
|
||||||
|
w.reserve(10);
|
||||||
|
assert(w.capacity >= 10);
|
||||||
|
|
||||||
|
w.put('a'); // single elements
|
||||||
|
w.put("bc"); // multiple elements
|
||||||
|
|
||||||
|
// use the append syntax
|
||||||
|
w ~= 'd';
|
||||||
|
w ~= "ef";
|
||||||
|
|
||||||
|
assert(w.data == "abcdef");
|
||||||
|
}
|
||||||
|
|
||||||
@safe pure nothrow unittest
|
@safe pure nothrow unittest
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -3597,6 +3666,23 @@ RefAppender!(E[]) appender(P : E[]*, E)(P arrayPtr)
|
||||||
return RefAppender!(E[])(arrayPtr);
|
return RefAppender!(E[])(arrayPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@system pure nothrow
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
int[] a = [1, 2];
|
||||||
|
auto app2 = appender(&a);
|
||||||
|
assert(app2.data == [1, 2]);
|
||||||
|
assert(a == [1, 2]);
|
||||||
|
app2 ~= 3;
|
||||||
|
app2 ~= [4, 5, 6];
|
||||||
|
assert(app2.data == [1, 2, 3, 4, 5, 6]);
|
||||||
|
assert(a == [1, 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
|
app2.reserve(5);
|
||||||
|
assert(app2.capacity >= 5);
|
||||||
|
}
|
||||||
|
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue