Preserving const? -- A potential solution
Tim M
a at b.com
Sat Mar 7 22:33:16 PST 2009
>> If you're not actually responding to a post, please don't quote the
>> entire thing in your message.
The subject should have been more accurate then but yes preserving
constness is very usefull though I prefer the inferred template way:
module tconst;
import std.stdio;
T max(T)(T a, T b)
{
if(a > b)
return a;
else
return b;
}
void main()
{
invariant int a = 2;
invariant int b = 4;
auto c = max(a,b); //c becomes an invariant int
c = 5; //should fail as c is also invariant
}
More information about the Digitalmars-d
mailing list