Re: Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread tcak via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 15:51:59 UTC, bearophile wrote: tcak: void dataProcessor( string giveMeAllYourData ){} dataProcessor( cast( immutable )( importantData[5 .. 14] ) ); With Const, void dataProcessor( in char[] giveMeAllYourData ){} dataProcessor( cast( const )( importantData[5 ..

Re: Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread bearophile via Digitalmars-d-learn
tcak: void dataProcessor( string giveMeAllYourData ){} dataProcessor( cast( immutable )( importantData[5 .. 14] ) ); With Const, void dataProcessor( in char[] giveMeAllYourData ){} dataProcessor( cast( const )( importantData[5 .. 14] ) ); Don't cast to const/immutable unless you have a g

Re: Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
If you're just looking at the data, use const. immutable becomes more important if it is shared across threads or stored for later. Functions that accept const will work with almost anything you pass to it.

Re: Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 15:11:39 UTC, tcak wrote: I have data in memory, and I want a function to take a part of data for processing only. It will only read and won't change. char[] importantData; With Immutable, void dataProcessor( string giveMeAllYourData ){} dataProcessor( cast( immu