const or immutable?

Ali Çehreli acehreli at yahoo.com
Thu Sep 23 22:46:04 UTC 2021


On 9/22/21 1:48 PM, Timon Gehr wrote:

 > No. I think `const` and especially `immutable` are great for plain old
 > data types, especially data that has multiple references to it. For
 > non-trivial user-defined data types, I think just using proper
 > encapsulation is usually sufficient and more flexible.

You mean, providing "const access" to an encapsulated entity through an 
accessor. Sure... Still, do you make 'const' local objects of such types 
or are they auto?

   const     a = MyStruct();
   immutable b = MyStruct();
   auto      c = MyStruct();  // This one?

Ali



More information about the Digitalmars-d mailing list