foo!(bar) ==> foo{bar} ==> foo[bar] (just Brackets)
ore-sama
spam at here.lot
Wed Oct 15 02:14:19 PDT 2008
Bruno Medeiros Wrote:
> Hum, what about brackets without any prefix character at all?
>
> Vector[int, 2] foo;
> List[Vector[int, 2]] bar;
> int[3] a = [1, 2, 3]; // array literal here
> int[int] map;
> alias DenseMatrix[num] PulType;
> alias SparseRowsMatrix[num, HashSparseVector] PuuType;
> alias BiMap[uint, Tuple[uint, uint], BiMapOptions.lhDense] DicType;
> int var = a[2]; // array indexing here
>
I had similar idea. I wondered, will it be nice to allow intermixing of template parameters with function parameters...
It obviously conflicts with array literals :)
//Range overlap(Range)(Range r1, Range r2);
Range overlap([Range], Range r1, Range r2);
//template reduce(F...)
template reduce([F...])
int[] arr = [ 1, 2, 3, 4, 5 ];
// Sum all elements
//auto sum = reduce!("a + b")(0, arr);
auto sum = reduce(["a + b"], 0, arr);
auto sum = reduce(0, arr, ["a + b"]);
// Compute the maximum of all elements
//auto largest = reduce!(max)(arr[0], arr[1 .. $]);
auto largest = reduce([max], arr[0], arr[1 .. $]);
double[] a = [ 3.0, 4, 7, 11, 3, 2, 5 ];
// Compute minimum and maximum in one pass
//auto r = reduce!(min, max)(double.max, -double.max, a);
auto r = reduce([min], [max], double.max, -double.max, a);
//size_t count(alias pred = "a == b", Range, E)(Range r, E value);
size_t count([alias pred = "a == b"], [Range] r, [E] value); //haa?
Range eliminate(alias pred = "a == b",
SwapStrategy ss = SwapStrategy.semistable,
Range, Value)(Range r, Value v)
{
alias Iterator!(Range) It;
bool comp(typeof(*It) a) { return !binaryFun!(pred)(a, v); }
static void assignIterB(It a, It b) { *a = *b; }
return range(begin(r),
partition!(comp,
ss, assignIterB, Range)(r));
}
Range eliminate([alias pred = "a == b"],
[SwapStrategy ss = SwapStrategy.semistable],
[Range] r, [Value] v)
{
alias Iterator([Range]) It;
bool comp(typeof(*It) a) { return !binaryFun([pred], a, v); }
static void assignIterB(It a, It b) { *a = *b; }
return range(begin(r),
partition([comp],
[ss], [assignIterB], r));
}
More information about the Digitalmars-d
mailing list