Creating Tuple or AliasSeq

ANtlord via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 7 03:26:24 PDT 2017


On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote:
>
> Here is a solution:
>
> auto objectFactory(ObjectType, Args...)(Args args) {
>     import std.algorithm : cartesianProduct, map;
>     import std.array : array;
>
>     return cartesianProduct(args).map!(a => 
> ObjectType(a.expand)).array;
> }
>
> struct Pair {
>     int number;
>     string name;
> }
>
> import std.stdio;
>
> void main() {
>     auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]);
>     auto pairSet = pairKit;
>     writeln(pairSet);
> }
>
> Ali

I can't understand. Documentation of cartesianProduct points out 
about finite arrays. At least one of arrays must be a inifinte 
array. As far as I know finite arrays is `int[3]` and infinite is 
`int[]` 
(https://dlang.org/library/std/range/primitives/is_infinite.html). Am I right?

If I am then I can't understand why DMD return error about finite 
ranges compiling following code.

	struct Hay {
		int a;
		@disable this(this);
		@disable this();
		this(int a){
			this.a = a;
		}
		
	}
	Hay[] params = [ Hay(1), Hay(23) ];
	auto products = cartesianProduct(params, params);

Error text:

> static assert  "cartesianProduct involving finite ranges must 
> have at least one finite forward range"

I noticed that removing disabling default constructors helps. 
Does that mean an array contains objects of a struct with 
disabled default constructor is finite?




More information about the Digitalmars-d-learn mailing list