.init property for char[] type

Justin Johansson procode at adam-dott-com.au
Tue Sep 22 05:07:14 PDT 2009


In a templated class (D1.0) along lines ...

class Foo(T) {
//..
  static T bar() { return T.init; }
//..
}

Foo!(int).bar() returns 0 and Foo!(char[]).bar() returns nil.

I'd much prefer (at least for my purposes) that (char[]).init returned an empty string rather than effectively a null pointer.  Is there a convenient solution for this, e.g. by specializing just the bar method of class Foo when T is char[], or by some other means?

Maybe this type of question best be asked on D.learn, but I do wonder if an empty string is a more reasonable initializer for char[] .. well maybe not .. I don't know .. I yield to your sensibilities.

Thanks to all.




More information about the Digitalmars-d mailing list