mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 08:30:33 +03:00
doc std.algorithm.fill
This commit is contained in:
parent
fa538354bd
commit
6eb0d70794
1 changed files with 42 additions and 22 deletions
|
@ -1632,26 +1632,35 @@ unittest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fills $(D range) with a $(D filler).
|
Assigns $(D value) to each element of input range $(D range).
|
||||||
|
|
||||||
|
Params:
|
||||||
|
range = an $(LINK2 std_range.html#isInputRange, input range) that exposes references to its elements
|
||||||
|
and has assignable elements
|
||||||
|
value = assigned to each element of range
|
||||||
|
|
||||||
|
See_Also:
|
||||||
|
$(LREF uninitializedFill)
|
||||||
|
$(LREF initializeAll)
|
||||||
*/
|
*/
|
||||||
void fill(Range, Value)(Range range, Value filler)
|
void fill(Range, Value)(Range range, Value value)
|
||||||
if (isInputRange!Range && is(typeof(range.front = filler)))
|
if (isInputRange!Range && is(typeof(range.front = value)))
|
||||||
{
|
{
|
||||||
alias T = ElementType!Range;
|
alias T = ElementType!Range;
|
||||||
|
|
||||||
static if (is(typeof(range[] = filler)))
|
static if (is(typeof(range[] = value)))
|
||||||
{
|
{
|
||||||
range[] = filler;
|
range[] = value;
|
||||||
}
|
}
|
||||||
else static if (is(typeof(range[] = T(filler))))
|
else static if (is(typeof(range[] = T(value))))
|
||||||
{
|
{
|
||||||
range[] = T(filler);
|
range[] = T(value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( ; !range.empty; range.popFront() )
|
for ( ; !range.empty; range.popFront() )
|
||||||
{
|
{
|
||||||
range.front = filler;
|
range.front = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1847,13 +1856,20 @@ void fill(Range1, Range2)(Range1 range, Range2 filler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fills a range with a value. Assumes that the range does not currently
|
Initializes each element of $(D range) with $(D value).
|
||||||
contain meaningful content. This is of interest for structs that
|
Assumes that the elements of the range are uninitialized.
|
||||||
define copy constructors (for all other types, fill and
|
This is of interest for structs that
|
||||||
|
define copy constructors (for all other types, $(LREF fill) and
|
||||||
uninitializedFill are equivalent).
|
uninitializedFill are equivalent).
|
||||||
|
|
||||||
uninitializedFill will only operate on ranges that expose references to its
|
Params:
|
||||||
members and have assignable elements.
|
range = an $(LINK2 std_range.html#isInputRange, input range) that exposes references to its elements
|
||||||
|
and has assignable elements
|
||||||
|
value = assigned to each element of range
|
||||||
|
|
||||||
|
See_Also:
|
||||||
|
$(LREF fill)
|
||||||
|
$(LREF initializeAll)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
----
|
----
|
||||||
|
@ -1863,8 +1879,8 @@ uninitializedFill(s, 42);
|
||||||
assert(s == [ 42, 42, 42, 42, 42 ]);
|
assert(s == [ 42, 42, 42, 42, 42 ]);
|
||||||
----
|
----
|
||||||
*/
|
*/
|
||||||
void uninitializedFill(Range, Value)(Range range, Value filler)
|
void uninitializedFill(Range, Value)(Range range, Value value)
|
||||||
if (isInputRange!Range && hasLvalueElements!Range && is(typeof(range.front = filler)))
|
if (isInputRange!Range && hasLvalueElements!Range && is(typeof(range.front = value)))
|
||||||
{
|
{
|
||||||
alias T = ElementType!Range;
|
alias T = ElementType!Range;
|
||||||
static if (hasElaborateAssign!T)
|
static if (hasElaborateAssign!T)
|
||||||
|
@ -1873,20 +1889,24 @@ void uninitializedFill(Range, Value)(Range range, Value filler)
|
||||||
|
|
||||||
// Must construct stuff by the book
|
// Must construct stuff by the book
|
||||||
for (; !range.empty; range.popFront())
|
for (; !range.empty; range.popFront())
|
||||||
emplaceRef!T(range.front, filler);
|
emplaceRef!T(range.front, value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// Doesn't matter whether fill is initialized or not
|
// Doesn't matter whether fill is initialized or not
|
||||||
return fill(range, filler);
|
return fill(range, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes all elements of a range with their $(D .init)
|
Initializes all elements of $(D range) with their $(D .init) value.
|
||||||
value. Assumes that the range does not currently contain meaningful
|
Assumes that the elements of the range are uninitialized.
|
||||||
content.
|
|
||||||
|
|
||||||
initializeAll will operate on ranges that expose references to its
|
Params:
|
||||||
members and have assignable elements, as well as on (mutable) strings.
|
range = an $(LINK2 std_range.html#isInputRange, input range) that exposes references to its elements
|
||||||
|
and has assignable elements
|
||||||
|
|
||||||
|
See_Also:
|
||||||
|
$(LREF fill)
|
||||||
|
$(LREF uninitializeFill)
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
----
|
----
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue