status of 'lazy' ?

Michiel nomail at please.com
Sat Feb 17 01:21:35 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:

> Just tell me
> quickly what "const inout lazy const char[]" means...

I'm not convinced that type expression makes sense. I understand why you
can probably make some parts of a type expression const and leave others
non-const (like: a const pointer to a non-const value, or the other way
around). But not how those two consts in a row there could make a
difference. Nor how const and inout would work together. (const would
probably neutralize the out.) Nor how const/lazy or inout/lazy would
work together. But I don't know enough about 'lazy' to get deep into that.

> I don't have time to get busy with it just now, but here's a warmup
> question: what should, and what shouldn't pass the semantic check below?
> 
> void Fun(T, U)(T t, U u)
> {
>   t = 0;
>   ++t;
>   u[0] = 'a';
>   u = "blah";
> }

I think it would be like this:

> void main()
> {
>   const int x = 0; // No problem
>   const char[] y = "wyda"; // No problem
>   Fun(x, y); // No problem
>   x = 1; // ERROR
>   y[0] = 'a'; // NOT CERTAIN
>   y = "geeba"; // ERROR
> }

Correct me if I'm wrong.

Now, I'm not sure if it's (const char)[] or const (char[]). In other
words: A const array of chars or an array of const chars. And I'm not
sure if the second version would make sense anyway. Would a const
(dynamic array) become a static array or something?

In either case, the last assignment fails, because you're changing both
the length and the content.

-- 
Michiel



More information about the Digitalmars-d mailing list