www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - clear() not implemented as object method?

reply Thomas Mader <thomas.mader gmail.com> writes:
I just wondered why clear() which is there to call the desctructor of an 
object is implemented as a module function instead of being an object 
method in object_d.
Is there a technical reason for it I don't recognise?

unittest {
     auto b = new Buffer;
     clear(b); // Wouldn't b.clear() be nicer?
}

Thomas
Mar 18 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 18 Mar 2011 13:13:27 -0400, Thomas Mader <thomas.mader gmail.com>  
wrote:

 I just wondered why clear() which is there to call the desctructor of an  
 object is implemented as a module function instead of being an object  
 method in object_d.
 Is there a technical reason for it I don't recognise?

 unittest {
      auto b = new Buffer;
      clear(b); // Wouldn't b.clear() be nicer?
 }
It's a template that handles any type, class object, struct instance, int, float, etc. -Steve
Mar 18 2011
parent Jesse Phillips <jessekphillips+D gmail.com> writes:
Steven Schveighoffer Wrote:

 On Fri, 18 Mar 2011 13:13:27 -0400, Thomas Mader <thomas.mader gmail.com>  
 wrote:
 
 I just wondered why clear() which is there to call the desctructor of an  
 object is implemented as a module function instead of being an object  
 method in object_d.
 Is there a technical reason for it I don't recognise?

 unittest {
      auto b = new Buffer;
      clear(b); // Wouldn't b.clear() be nicer?
 }
It's a template that handles any type, class object, struct instance, int, float, etc. -Steve
also b.clear() is a Container function for emptying the container.
Mar 18 2011