Shall I use immutable or const while passing parameters to functions
tcak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 7 08:11:38 PDT 2015
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( immutable )( importantData[5 .. 14] ) );
With Const,
void dataProcessor( in char[] giveMeAllYourData ){}
dataProcessor( cast( const )( importantData[5 .. 14] ) );
(Code with const wasn't tested)
Which one is better? I didn't understand it very well in
http://dlang.org/const3.html this page.
More information about the Digitalmars-d-learn
mailing list