On 2010-10-18 17:25:49 -0400, Tomek Sowiński <j...@ask.me> said:

Thanks for support. I see two ways to go about it:

pure T make(Args args) { ... }
unittest {
     T t = make(...); // good
     immutable T t = make(...); // also good
}

Or:

pure immutable(T) make(Args args) {
     T t = ...;
     // initialize t
     return t; // conversion happens here
}

I like the first one.

The first one has one interesting property: if at the call site you know that all the arguments you're feeding the function with are immutable, then you can automatically cast the result to immutable, even if the function can also accept const arguments.

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to