View source code
							
							
						
								Display the source code in std/range/primitives.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Module std.range.primitives
This module is a submodule of std.
It defines the bidirectional and forward range primitives for arrays:
empty, front, back, popFront, popBack and save.
It provides basic range functionality by defining several templates for testing whether a given object is a range, and what kind of range it is:
| isInputRange | Tests if something is an input range, defined to be
        something from which one can sequentially read data using the
        primitives front,popFront, andempty. | 
| isOutputRange | Tests if something is an output range, defined to be
        something to which one can sequentially write data using the putprimitive. | 
| isForwardRange | Tests if something is a forward range, defined to be an
        input range with the additional capability that one can save one's
        current position with the saveprimitive, thus allowing one to
        iterate over the same range multiple times. | 
| isBidirectionalRange | Tests if something is a bidirectional range, that is, a
        forward range that allows reverse traversal using the primitives         backandpopBack. | 
| isRandomAccessRange | Tests if something is a random access range, which is a
        bidirectional range that also supports the array subscripting
        operation via the primitive opIndex. | 
It also provides number of templates that test for various range capabilities:
| hasMobileElements | Tests if a given range's elements can be moved around using the
        primitives moveFront,moveBack, ormoveAt. | 
| ElementType | Returns the element type of a given range. | 
| ElementEncodingType | Returns the encoding element type of a given range. | 
| hasSwappableElements | Tests if a range is a forward range with swappable elements. | 
| hasAssignableElements | Tests if a range is a forward range with mutable elements. | 
| hasLvalueElements | Tests if a range is a forward range with elements that can be passed by reference and have their address taken. | 
| hasLength | Tests if a given range has the lengthattribute. | 
| isInfinite | Tests if a given range is an infinite range. | 
| hasSlicing | Tests if a given range supports the array slicing operation         R[x .. y]. | 
Finally, it includes some convenience functions for manipulating ranges:
| popFrontN | Advances a given range by up to n elements. | 
| popBackN | Advances a given bidirectional range from the right by up to n elements. | 
| popFrontExactly | Advances a given range by up exactly n elements. | 
| popBackExactly | Advances a given bidirectional range from the right by exactly n elements. | 
| moveFront | Removes the front element of a range. | 
| moveBack | Removes the back element of a bidirectional range. | 
| moveAt | Removes the i'th element of a random-access range. | 
| walkLength | Computes the length of any range in O(n) time. | 
| put | Outputs element eto a range. | 
Functions
| Name | Description | 
|---|---|
| 
									back(a)
								 | Implements the range interface primitive backfor built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation,arrayis
equivalent toback(array). For narrow strings,backautomatically returns the last code point as adchar. | 
| 
									empty(a)
								 | Implements the range interface primitive emptyfor types that
obeyhasLengthproperty and for narrow strings. Due to the
fact that nonmember functions can be called with the first argument
using the dot notation,ais equivalent toempty(a). | 
| 
									front(a)
								 | Implements the range interface primitive frontfor built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation,arrayis
equivalent tofront(array). For narrow strings,frontautomatically returns the first code point as adchar. | 
| 
									moveAt(r, i)
								 | Moves element at index iofrout and returns it. Leaves   r[i]in a destroyable state that does not allocate any resources
   (usually equal to itsvalue). | 
| 
									moveBack(r)
								 | Moves the back of rout and returns it. Leavesrin a
   destroyable state that does not allocate any resources (usually equal
   to itsvalue). | 
| 
									moveFront(r)
								 | Moves the front of rout and returns it. Leavesrin a
   destroyable state that does not allocate any resources (usually equal
   to itsvalue). | 
| 
									popBack(a)
								 | Implements the range interface primitive popBackfor built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation,arrayis
equivalent topopBack(array). For narrow strings,popFrontautomatically eliminates the last code point. | 
| 
									popBackExactly(r, n)
								 | Eagerly advances ritself (not a copy) exactlyntimes (by
    callingr).popFrontExactlytakesrbyref,
    so it mutates the original range. Completes in Ο(1) steps for ranges
    that support slicing, and have either length or are infinite.
    Completes in Ο(n) time for all other ranges. | 
| 
									popBackN(r, n)
								 | popFrontNeagerly advancesritself (not a copy) up tontimes
    (by callingr).popFrontNtakesrbyref,
    so it mutates the original range. Completes in Ο(1) steps for ranges
    that support slicing and have length.
    Completes in Ο(n) time for all other ranges. | 
| 
									popFront(a)
								 | Implements the range interface primitive popFrontfor built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation,arrayis
equivalent topopFront(array). For narrow strings,popFrontautomatically advances to the next code
point. | 
| 
									popFrontExactly(r, n)
								 | Eagerly advances ritself (not a copy) exactlyntimes (by
    callingr).popFrontExactlytakesrbyref,
    so it mutates the original range. Completes in Ο(1) steps for ranges
    that support slicing, and have either length or are infinite.
    Completes in Ο(n) time for all other ranges. | 
| 
									popFrontN(r, n)
								 | popFrontNeagerly advancesritself (not a copy) up tontimes
    (by callingr).popFrontNtakesrbyref,
    so it mutates the original range. Completes in Ο(1) steps for ranges
    that support slicing and have length.
    Completes in Ο(n) time for all other ranges. | 
| 
									put(r, e)
								 | Outputs etor. The exact effect is dependent upon the two
types. Several cases are accepted, as described below. The code snippets
are attempted in order, and the first to compile "wins" and gets
evaluated. | 
| 
									save(a)
								 | Implements the range interface primitive savefor built-in
arrays. Due to the fact that nonmember functions can be called with
the first argument using the dot notation,arrayis
equivalent tosave(array). The function does not duplicate the
content of the array, it simply returns its argument. | 
| 
									walkLength(range)
								 | This is a best-effort implementation of lengthfor any kind of
range. | 
Manifest constants
| Name | Type | Description | 
|---|---|---|
| autodecodeStrings | ||
| hasAssignableElements | Returns trueifRis an input range and has mutable
elements. The following code should compile for any range
with assignable elements. | |
| hasLength | Yields trueifRhas alengthmember that returns a value ofsize_ttype.Rdoes not have to be a range. IfRis a range, algorithms in the
standard library are only guaranteed to supportlengthwith typesize_t. | |
| hasLvalueElements | Tests whether the range Rhas lvalue elements. These are defined as
elements that can be passed by reference and have their address taken.
The following code should compile for any range with lvalue elements. | |
| hasMobileElements | Returns trueiffRis an input range that supports themoveFrontprimitive, as well asmoveBackandmoveAtif it's a
bidirectional or random access range. These may be explicitly implemented, or
may work via the default behavior of the module level functionsmoveFrontand friends. The following code should compile for any range
with mobile elements. | |
| hasSlicing | Returns trueifRoffers a slicing operator with integral boundaries
that returns a forward range type. | |
| hasSwappableElements | Returns trueifRis an input range and has swappable
elements. The following code should compile for any range
with swappable elements. | |
| isBidirectionalRange | Returns trueifRis a bidirectional range. A bidirectional
range is a forward range that also offers the primitivesbackandpopBack. The following code should compile for any bidirectional
range. | |
| isForwardRange | Returns trueifRis a forward range. A forward range is an
input rangerthat can save "checkpoints" by savingrto another value of typeR. Notable examples of input ranges that
are not forward ranges are file/socket ranges; copying such a
range will not save the position in the stream, and they most likely
reuse an internal buffer as the entire stream does not sit in
memory. Subsequently, advancing either the original or the copy will
advance the stream, so the copies are not independent. | |
| isInfinite | Returns trueifRis an infinite input range. An
infinite input range is an input range that has a statically-defined
enumerated member calledemptythat is alwaysfalse,
for example: | |
| isInputRange | Returns trueifRis an input range. An input range must
define the primitivesempty,popFront, andfront. The
following code should compile for any input range. | |
| isOutputRange | Returns trueifRis an output range for elements of typeE. An output range is defined functionally as a range that
supports the operationput(r, e)as defined above. | |
| isRandomAccessRange | Returns trueifRis a random-access range. A random-access
range is a bidirectional range that also offers the primitiveopIndex, OR an infinite forward range that offersopIndex. In
either case, the range must either offerlengthor be
infinite. The following code should compile for any random-access
range. | 
Aliases
| Name | Type | Description | 
|---|---|---|
| ElementEncodingType | E | The encoding element type of R. For narrow strings (char[],wchar[]and their qualified variants includingstringandwstring),ElementEncodingTypeis the character type of the
string. For all other types,ElementEncodingTypeis the same asElementType. | 
| ElementType | T | The element type of R.Rdoes not have to be a range. The
element type is determined as the type yielded byrfor an
objectrof typeR. For example,ElementType!(T[])isTifT[]isn't a narrow string; if it is, the element type isdchar. IfRdoesn't havefront,ElementType!Risvoid. | 
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.