d链接区间
import std.algorithm : sort;
import std.conv : to;
import std.range;
import std.stdio;
enum limit = 5;
enum step = limit / 10.0;/*
enum step = 1; //*/
void main()
{
TypeInfo rangeType;
auto a = iota(limit);
auto b = iota(step, limit, step);
/* <- 切换注解,请加-> /
auto ab = chain(a, b);
rangeType = typeid(ab);/*/
auto arrA = a.array.to!(double[]);
auto arrB = b.array;
auto ab = chain(arrA, arrB);
rangeType = typeid(ab.sort);//*/
ab.writeln(": ", rangeType);
} /*
current print:
==============
[0, 0.5, 1, 1, 1.5, 2, 2, 2.5, 3, 3, 3.5, 4, 4, 4.5]: std.range.SortedRange!(std.range.chain!(double[], double[]).chain(double[], double[]).Result, "a < b", 0).SortedRange
other print:
============
[0, 1, 2, 3, 4, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5]: std.range.chain!(std.range.iota!(int, int).iota(int, int).Result, std.range.iota!(double, int, double).iota(double, int, double).Result).chain(std.range.iota!(int, int).iota(int, int).Result, std.range.iota!(double, int, double).iota(double, int, double).Result).Result
不同类型(其中一个是double
)但相同区间可用chain()
链接.但是,因为opCmp()
与排序
等算法的兼容性
,需要转换为数组
.