Difference between revisions of "DIP67"
Superstar64 (talk | contribs) |
Superstar64 (talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
|- | |- | ||
|Status: | |Status: | ||
− | | | + | |'''Rejected''' |
|- | |- | ||
|Created: | |Created: | ||
Line 16: | Line 16: | ||
|- | |- | ||
|Last Modified: | |Last Modified: | ||
− | |2014-10- | + | |2014-10-31 |
|- | |- | ||
|Author: | |Author: | ||
Line 48: | Line 48: | ||
== Usage == | == Usage == | ||
<syntaxhighlight lang="d"> | <syntaxhighlight lang="d"> | ||
+ | import std.range; | ||
struct AssociativeRange | struct AssociativeRange | ||
{ | { | ||
− | float | + | InputRange!float byKey; |
− | uint | + | InputRange!uint byValue; |
uint opIndex(float); | uint opIndex(float); | ||
const (uint)* opBinaryRight(string op)(float) if(op=="in"); | const (uint)* opBinaryRight(string op)(float) if(op=="in"); | ||
Line 60: | Line 61: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="d"> | <syntaxhighlight lang="d"> | ||
+ | import std.range; | ||
struct LazyAssociativeRange | struct LazyAssociativeRange | ||
{ | { | ||
Line 70: | Line 72: | ||
alias V=ElementValueType!LazyAssociativeRange; | alias V=ElementValueType!LazyAssociativeRange; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
== Copyright == | == Copyright == | ||
This document has been placed in the Public Domain. | This document has been placed in the Public Domain. | ||
[[Category: DIP]] | [[Category: DIP]] |
Latest revision as of 23:27, 31 October 2014
Title: | Associative Ranges |
---|---|
DIP: | 67 |
Version: | 1 |
Status: | Rejected |
Created: | 2014-10-28 |
Last Modified: | 2014-10-31 |
Author: | Freddy "superstar64" Cubas |
Links: |
Contents
Abstract
Introduce Associative ranges and lazy associative ranges to phobos. A associative range is a user defined container that has all the features of a build-in associative array. A lazy associative range is a sub set of a associative with only a index operator(of any type)
Rationale
Allow abtraction of hashmaps with ranges.
Description
An associative range must have: A byKey attribute that returns an input range of keys, A byValue attribute that returns an input range of values, byKey and byValue must be align to the same Pair when iterating. An index operator that takes a key and returns a value. An in operator that takes a key and returns a value pointer(or a user defined type that acts like one) or null if it doesn't exist.
A lazy associative range must have: An alias to the key type "KeyType" An alias to the value type "ValueType" An index operator that takes a key type and returns value.
Usage
import std.range;
struct AssociativeRange
{
InputRange!float byKey;
InputRange!uint byValue;
uint opIndex(float);
const (uint)* opBinaryRight(string op)(float) if(op=="in");
}
static assert(isAssociativeRange!AssociativeRange);
alias K=ElementKeyType!AssociativeRange;
alias V=ElementValueType!AssociativeRange;
import std.range;
struct LazyAssociativeRange
{
alias KeyType=double;
alias ValueType=float;
float opIndex(double);
}
static assert(isLazyAssociativeRange!LazyAssociativeRange);
alias K=ElementKeyType!LazyAssociativeRange;
alias V=ElementValueType!LazyAssociativeRange;
Copyright
This document has been placed in the Public Domain.