www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How convert DList!string to string array

reply "Denis Mezhov" <d.o.mezhov gmail.com> writes:
Please help. How to convert DList!string to string array?

auto a = DList!string();
a.insertFront("123");
a.insertFront("abc");

string[] b = a[];
Array!string c = a[];

Don't work.
Feb 15 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/15/2014 05:30 PM, Denis Mezhov wrote:
 Please help. How to convert DList!string to string array?

 auto a = DList!string();
 a.insertFront("123");
 a.insertFront("abc");

 string[] b = a[];
 Array!string c = a[];

 Don't work.
auto b = a[].array; Array!string c; c.insertBack(a[]);
Feb 15 2014
next sibling parent "Denis Mezhov" <d.o.mezhov gmail.com> writes:
On Saturday, 15 February 2014 at 16:38:42 UTC, Timon Gehr wrote:
 On 02/15/2014 05:30 PM, Denis Mezhov wrote:
 Please help. How to convert DList!string to string array?

 auto a = DList!string();
 a.insertFront("123");
 a.insertFront("abc");

 string[] b = a[];
 Array!string c = a[];

 Don't work.
auto b = a[].array; Array!string c; c.insertBack(a[]);
It works! Thanks for the quick reply.
Feb 15 2014
prev sibling next sibling parent reply "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Saturday, 15 February 2014 at 16:38:42 UTC, Timon Gehr wrote:
 On 02/15/2014 05:30 PM, Denis Mezhov wrote:
 Please help. How to convert DList!string to string array?

 auto a = DList!string();
 a.insertFront("123");
 a.insertFront("abc");

 string[] b = a[];
 Array!string c = a[];

 Don't work.
auto b = a[].array; Array!string c; c.insertBack(a[]);
You can construct containers from ranges directly: auto c = Array!string(a[]);
Feb 15 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/15/2014 06:11 PM, Jakob Ovrum wrote:
 ...

 You can construct containers from ranges directly:

 auto c = Array!string(a[]);
This seems obvious, but it is not actually true.
Feb 15 2014
parent reply "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Saturday, 15 February 2014 at 18:14:00 UTC, Timon Gehr wrote:
 On 02/15/2014 06:11 PM, Jakob Ovrum wrote:
 ...

 You can construct containers from ranges directly:

 auto c = Array!string(a[]);
This seems obvious, but it is not actually true.
It is a defined container primitive. The first one in the table, in fact.
Feb 15 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/15/2014 07:23 PM, Jakob Ovrum wrote:
 On Saturday, 15 February 2014 at 18:14:00 UTC, Timon Gehr wrote:
 On 02/15/2014 06:11 PM, Jakob Ovrum wrote:
 ...

 You can construct containers from ranges directly:

 auto c = Array!string(a[]);
This seems obvious, but it is not actually true.
It is a defined container primitive. The first one in the table, in fact.
Array does not implement this primitive. http://dpaste.dzfl.pl/a8cb1064bd08
Feb 15 2014
parent "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Saturday, 15 February 2014 at 18:30:39 UTC, Timon Gehr wrote:
 On 02/15/2014 07:23 PM, Jakob Ovrum wrote:
 On Saturday, 15 February 2014 at 18:14:00 UTC, Timon Gehr 
 wrote:
 On 02/15/2014 06:11 PM, Jakob Ovrum wrote:
 ...

 You can construct containers from ranges directly:

 auto c = Array!string(a[]);
This seems obvious, but it is not actually true.
It is a defined container primitive. The first one in the table, in fact.
Array does not implement this primitive. http://dpaste.dzfl.pl/a8cb1064bd08
That seems gratuitous. If there's no particular reason it doesn't implement it, I would consider it a bug. It is arguably the most basic container primitive.
Feb 15 2014
prev sibling parent "Jesse Phillips" <Jesse.K.Phillips+D gmail.com> writes:
On Saturday, 15 February 2014 at 16:38:42 UTC, Timon Gehr wrote:
 On 02/15/2014 05:30 PM, Denis Mezhov wrote:
 Please help. How to convert DList!string to string array?

 auto a = DList!string();
 a.insertFront("123");
 a.insertFront("abc");

 string[] b = a[];
 Array!string c = a[];

 Don't work.
auto b = a[].array; Array!string c; c.insertBack(a[]);
I just wanted to point out: auto b = a[].array; That is unrelated to c, which is a conversion to Array, while this is a conversion to an array.
Feb 15 2014