Writing const-correct code in D
Andrew Fedoniouk
news at terrainformatica.com
Wed Mar 8 12:19:29 PST 2006
> I think having seperate overloads for const and non-const parameters is a
> design mistake in C++. I see C++ 'const' as a compile-time contract, not a
> type. IMHO, overloading const vs non-const is like overloading functions
> based on their contracts.
>
> I suspect that 'const' has exaggerated importance to those of us from a
> C++ background, because it's almost the only contract that C++ provides.
> Maybe the solution to 'const' is a more general compile-time contract
> mechanism.
Let's say we have two declarations:
T[] and readonly T[]
These two describe two different types - they have two different sets of
methods:
T[] has opSliceAssign and opIndexAssign.
in contrary readonly T[] has no such methods.
This is why they are two distinct types. And it is highly desirable that
they will be treated
as types and not as any sort of contracts. Think about template
instantiation, static if's and so on.
Andrew Fedoniouk.
http://terrainformatica.com
More information about the Digitalmars-d
mailing list