Immutability and other attributes, please review
    Roman D. Boiko 
    rb at d-coding.com
       
    Thu Jun 14 03:31:16 PDT 2012
    
    
  
On Thursday, 14 June 2012 at 09:56:08 UTC, Roman D. Boiko wrote:
> By the way, the whole data model is designed to be immutable. 
> Should I replace const with immutable then?
The other thing I don't like is having to cast everywhere:
struct Maybe(T)
{
   immutable T* payload; // pointer to data
   pure nothrow this(T* payload)
   {
     this.payload = cast(immutable) payload;
   }
   pure nothrow @property T front() const in{ assert(!empty); }
   body{ return cast(T) *payload; }
   //...
}
OTOH, I'm not sure making input parameter immutable would be 
better for the user, same for function return type.
    
    
More information about the Digitalmars-d-learn
mailing list