www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "only" vs "[]"

reply pascal111 <judas.the.messiah.111 gmail.com> writes:
The output of next code is the same to extent that we feel that 
there's no difference between "only" and "[]", so what "only" 
added here?:

'''D
[1,2,3].writeln;
only(1,2,3).writeln;
'''

output:

[1, 2, 3]
[1, 2, 3]
Aug 08 2022
parent vit <vit vit.vit> writes:
On Monday, 8 August 2022 at 11:35:48 UTC, pascal111 wrote:
 The output of next code is the same to extent that we feel that 
 there's no difference between "only" and "[]", so what "only" 
 added here?:

 '''D
 [1,2,3].writeln;
 only(1,2,3).writeln;
 '''

 output:

 [1, 2, 3]
 [1, 2, 3]
`only(1,2,3)` doesn't use GC. `[1,2,3]` allocate GC array.
Aug 08 2022