"invariant" vs. "const"

AJ aj at nospam.net
Thu Nov 5 14:58:35 PST 2009


A. String literal in D (not zero-terminated, immutable):

    invariant(char)[] lit = "abc";

B. String literal in C++ (zero-terminated, immutable):

    const char* lit = "abc";  // "const" here is redundant?

C. const array of characters in C++ (zero-terminated, mutable if const is 
cast away):

    const char[] lit = "abc";

(Aside: I'm not sure if C is a good replacement for B or if it was even 
intended to be so.)

I'm not sure how to think about "invariant". I think that "const" is 
overloaded so much in C++ that it leads to confusion. I think the answer 
lies somewhere in the distinctions between "const storage class" and "const 
type", of which "invariant is the former?






More information about the Digitalmars-d mailing list